ghow append dictonary pyhton code example
Example 1: Python dictionary append
testing1={'one':1,'two':2}
''' update() is the method of dict() merges another dict into existing ones '''
''' it replaces the keys of exisiting ones with the the new ones '''
testing1.update({'two':3,'noice':69})
print(testing1) """ {'one':1,'two':3,'noice':69} """
Example 2: append to dictionary python
# Append to Dictionary in Python
# Let's say we had the following dictionary:
languages = {'#1': "Python", "#2": "Javascript", "#3": "HTML"}
# There are two ways to add a key-and-value set to this dictionary
# Number 1: By .update() method
languages.update({"#4": "C#"}) # Adds a #4 key-and-value set
#--------------------------------------------
# Number 2: The define-key method
# This is the easier one
languages['#4'] = 'C#'
# ^^ Just updates a key of #4 to C#, or adds it in this case