...

/

Built-in Functions and Dictionary Methods

Built-in Functions and Dictionary Methods

Learn about the usage of some built-in functions and methods of the dictionary.

Using built-in functions on dictionaries

Many built-in functions can be used with dictionaries, as demonstrated below:

Press + to interact
d = { 'CS101' : 'CPP', 'CS102' : 'DS', 'CS201' : 'OOP'}
print(len(d)) # return number of key-value pairs
print(max(d)) # return maximum key in dictionary d
print(min(d)) # return minimum key in dictionary d
print(sorted(d)) # return sorted list of keys
print(any(d)) # return True if any key of dictionary d is True
print(all(d)) # return True if all keys of dictionary d are True
print(reversed(d)) # can be used for reversing dict/keys/values
n = {1 : "Python", 2 : "C++", 3 : "Java"}
print(sum(n)) # return sum of all keys if keys are numbers

The usage of the ...