The document lists various functions that can be used with dictionaries in Python, along with their formats. Functions include 'len' for length, 'min' and 'max' for minimum and maximum elements, 'sum' for total, and methods for accessing keys, values, and items. It also describes functions for modifying dictionaries, such as 'copy', 'clear', 'pop', and 'update'.
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
1 views
Dictionary Functions
The document lists various functions that can be used with dictionaries in Python, along with their formats. Functions include 'len' for length, 'min' and 'max' for minimum and maximum elements, 'sum' for total, and methods for accessing keys, values, and items. It also describes functions for modifying dictionaries, such as 'copy', 'clear', 'pop', and 'update'.
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
FUNCTIONS IN DICTIONARIES :
Name Function Format
len - tells length of a dictionary
len(d1) min - displays min element of dictionary min(d1) max - displays max element of dictionary max(d1) sum - displays sum of elements in a dictionary sum(d1) get - displays value of any particular key d1.get(key) items - displays a sequence of (key,value) in pairs d1.items() keys - displays all the keys in a dictionary d1.keys() values - displays all the values in a dictionary d1.values() copy - creates a copy of dictionary d1.copy() clear - removes everything from the dictionary d1.clear() sorted - sorts keys in ascending/descending order sorted(d1)/sorted(d1,reverse=True) popitem - removes and displays the last pair of dictionary d1.popitem() pop - removes any particular pair on basis on key entered d1.pop() fromkeys - creates a new dictionary of entered key and value d1.fromkeys(key,value) setdefault - inserts new key:value pair in already existing dictionary d1.setdefault(key,value) update - adds elements of other dict (d2) to main dict (d1) d1.update(d2)