Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python dictionary add item

# empty dictionary
dictionary = {}
# lists
list_1 = [1, 2, 3, 4, 5]
list_2 = ["e", "d", "c", "b", "a"]
# populate a dictionary.
for key, value in zip(list_1, list_2):
    dictionary[key] = value
# original
print(f"Original dictionary: {dictionary}")
# Add new item to the dictionary
dictionary[6] = "f"
# Updated dictionary
print(f"updated dictionary: {dictionary}")
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #dictionary #add #item
ADD COMMENT
Topic
Name
5+3 =