# This is our example dictionary
petAges = {"Cat": 4, "Dog": 2, "Fish": 1, "Parrot": 5}
# This will be our list, epmty for now
petAgesList = []
# Search through the dictionary and find all the keys and values
for key, value in petAges.items():
petAgesList.append([key, value]) # Add the key and value to the list
print(petAgesList) # Print the now-filled list
# Output: [['Cat', 4], ['Dog', 2], ['Fish', 1], ['Parrot', 5]]
#dictionary of lists to list of dictionaries:
v = [dict(zip(DL,t)) for t in zip(*DL.values())]
print(v)
# and back
v = {k: [dic[k] for dic in LD] for k in LD[0]}
print(v)
# Declaring a dictionary
d = {}
# This is the list which we are
# trying to use as a key to
# the dictionary
a =[1, 2, 3, 4, 5]
# converting the list a to a string
p = str(a)
d[p]= 1
# converting the list a to a tuple
q = tuple(a)
d[q]= 1
for key, value in d.items():
print(key, ':', value)
create list of dictionaries from list of list python
list_of_dict = []
for row in list_of_list[1:]: # Taking 0 index as header or key and rest as value
list_of_dict.append({key: val for key, val in list(zip(*[list_of_list[0], row]))})