Built-in Functions and Dictionary Methods
Learn about the usage of some built-in functions and methods of the dictionary.
We'll cover the following...
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 pairsprint(max(d)) # return maximum key in dictionary dprint(min(d)) # return minimum key in dictionary dprint(sorted(d)) # return sorted list of keysprint(any(d)) # return True if any key of dictionary d is Trueprint(all(d)) # return True if all keys of dictionary d are Trueprint(reversed(d)) # can be used for reversing dict/keys/valuesn = {1 : "Python", 2 : "C++", 3 : "Java"}print(sum(n)) # return sum of all keys if keys are numbers
The usage of the ...