Convert a list of dictionaries to a list of lists.

In this python dictionary program, we will convert a list of dictionaries to a list of lists.

Steps to solve the program
  1. Take a list of dictionaries as input and create an empty list.
  2. Use for loop to iterate over the dictionary in the list.
  3. Use a nested for loop to iterate over keys of the dictionary and create an empty list inside the loop.
  4. Add the keys to that list and add the list to the first empty list.
  5. Repeat this process for the values of the dictionary.
  6. 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]]
				
			

convert a key value list dictionary into a list of list.

count a number of items in a dictionary value that is in a list.

Leave a Comment