In this python dictionary program, we will convert a list of dictionaries to a list of lists.
Steps to solve the program
- Take a list of dictionaries as input and create an empty list.
- Use for loop to iterate over the dictionary in the list.
- Use a nested for loop to iterate over keys of the dictionary and create an empty list inside the loop.
- Add the keys to that list and add the list to the first empty list.
- Repeat this process for the values of the dictionary.
- Print the output.
dict1 = [{'sqa':123,'tools':456}]
l = []
for i in dict1:
for k in i.keys():
a = []
a.append(k)
l.append(a)
for v in i.values():
b = []
b.append(v)
l.append(b)
print(l)
Output :
[['sqa'], ['tools'], [123], [456]]