Search⌘ K
AI Features

Built-in Functions and Dictionary Methods

Explore how to apply built-in functions and dictionary methods in Python to efficiently manage data. Learn to reverse dictionary keys, update values safely, retrieve items with get(), and remove entries using popitem(). This lesson helps build foundational skills for handling dictionary data structures.

Using built-in functions on dictionaries

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

Python 3.8
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 ...