Name

.update()

Examples

element_names = {'H': 'hydrogen', 'He': 'helium', 'Li': 'lithium'}
additional_elements = {'B': 'boron', 'C': 'carbon', 'N': 'nitrogen'}

print(len(element_names)) # Prints 3

# "Update" original dictionary with new values
element_names.update(additional_elements)

print(len(element_names)) # Prints 6
print(element_names['N']) # Prints "Nitrogen"

# Updating with an existing key will overwrite the value for that key!
wrong_elements_oh_no = {'H': 'Happiness'}
element_names.update(wrong_elements_oh_no)

print(element_names['H']) # Prints "Happiness"

Description
Syntax
	dict1.update(dict2)
Parameters
dict1
dict2
Related Dictionary
Updated on Wed Jan 18 17:32:21 2017.
Creative Commons License