Convert a key value list dictionary into a list of lists.

In this python dictionary program, we will convert a key value list dictionary into a list of lists.

Steps to solve the program
  1. Take a dictionary as input and create an empty list.
  2. Use for loop to iterate over keys and values of the input dictionary.
  3. Create an empty list inside the for loop.
  4. First, add the key to the empty list using append().
  5. Now using a nested for loop iterate over a list of values and add them to the empty list using append().
  6. Now add this list to the first empty list.
  7. Repeat this process for each key-value pair.
  8. Print the output.
				
					dict1 = {'sqa':[1,4,6],'tools':[3,6,9]}
list1 = []

for key,val in dict1.items():
    l = []
    l.append(key)
    for ele in val:
        l.append(ele)
    list1.append(list(l))
    
print(list1)
				
			

Output :

				
					[['sqa', 1, 4, 6], ['tools', 3, 6, 9]]
				
			

print a dictionary line by line.

convert a list of dictionary to a list of lists.

Leave a Comment