python store key value pairs code example

Example 1: python create dictionary from key value

>>> L1 = ['a','b','c','d']
>>> L2 = [1,2,3,4]
>>> d = dict(zip(L1,L2))
>>> d
{'a': 1, 'b': 2, 'c': 3, 'd': 4}

Example 2: for key value in dict python

a_dict = {"color": "blue", "fruit": "apple", "pet": "dog"}
for key in a_dict:
  print(key, '->', a_dict[key])

# Output:
# color -> blue
# fruit -> apple
# pet -> dog

Example 3: python key value pair list

student = {"first_name": "Henry", "last_name": "Smith", "age": 20} # key: value

print(student["first_name"])
>>> Henry