Python - Dictionary Dictionary Update


Dictionaries, like lists, are mutable, so you can change, expand, and shrink them in place without making new dictionaries.

The del statement deletes the entry associated with the key specified as an index.

All collection data types in Python can nest inside each other arbitrarily:


D = {'eggs': 3, 'test': 2, 'ham': 1} 
D['ham'] = ['grill', 'bake', 'fry']           # Change entry (value=list) 
print( D )

del D['eggs']                                 # Delete entry 
print( D )

D['brunch'] = 'Bacon'                         # Add new entry 
print( D )


Assigning to an existing index in a dictionary changes its associated value.

Whenever assigning a new dictionary key you create a new entry in the dictionary.

Related Topics