Page 95 - Modular v1.1 Pyhton
P. 95
copy( ) Creates a shallow copy
items( ) Returns a new view of dictionary items
keys( ) Returns a new view of dictionary keys
update([other]) Updates the dictionary with the specified key and value
get(key) Returns the value of key
PYTHON FUNCTIONS
Python provides various built-in functions. The following table describes these functions.
Function Explanation
sorted( ) Sorts the elements
len( ) Returns the length
cmp( ) Compare items of the dictionaries
any( ) Returns true if any of the dictionary item is true
all( ) Returns true if all the dictionary items are true
UPDATING A DICTIONARY
You can easily add or modify the elements of a dictionary. If the item is present in the dictionary,
then you can change its value by providing new value to its key term.
Program 3: To update a dictionary.
On running the above program, you will get the following output:
REMOVING OR DELETING ELEMENTS OF A DICTIONARY
As you know, the pop( ) method is used to remove the dictionary element with the specified
key. The clear( ) method is used to remove all the elements of a dictionary and the popitem( )
method is used to remove any element from the Python dictionary. The del method is used to
delete a specific element or entire dictionary.
Dictionary in Python 93

