Python: Dictionary Operations in details

16 days ago
63

Python has a set of built-in methods that you can use on dictionaries.
1) clear(): Removes all the elements from the dictionary
2) copy(): Returns a copy of the dictionary
3) fromkeys(): Returns a dictionary with the specified keys and value
4) get(): Returns the value of the specified key
5) items(): Returns a list containing a tuple for each key value pair
6) keys(): Returns a list containing the dictionary's keys
7) pop(): Removes the element with the specified key
8) popitem(): Removes the last inserted key-value pair
9) setdefault(): Returns the value of the specified key. If the key does not exist: insert the key, with the specified value
10) update(): Updates the dictionary with the specified key-value pairs
11) values(): Returns a list of all the values in the dictionary

Loading comments...