key value pair python 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: dictionary in python
# Dictionaries in Python
ages = {"John": 43, "Bob": 24, "Ruth": 76} # Marked by { at beginning and a } at end
# ^^^ Has sets of keys and values, like the 'John' and 43 set. These two values must be seperated by a colon
# ^^^ Sets of values seperated by commas.
Example 3: python dict access
my_dict = {'name':'Jack', 'age': 26}
my_dict['name']
Example 4: how to load multiple list of dictionary values which is stored in python file and load into another python file in python over loop
for d in datathing: # remember that datathing is a list
print(d['created_on'], '--',
d['status'] + ':')
print(d['body'])
print("")
Example 5: python key value pair list
student = {"first_name": "Henry", "last_name": "Smith", "age": 20} # key: value
print(student["first_name"])
>>> Henry