Write a Python3 code to demonstrate working of Convert List of Dictionaries to List of Lists Using list comprehension


Topic: Write a Python3 code to demonstrate working of Convert List of Dictionaries to List of Lists Using list comprehension

Solution

test_list = [{'Nikhil' : 17, 'Akash' : 18, 'Akshat' : 20}, 
            {'Nikhil' : 21, 'Akash' : 30, 'Akshat' : 10}, 
            {'Nikhil' : 31, 'Akash' : 12, 'Akshat' : 19}] 
print("The original list is : " + str(test_list)) 
res = [[key for key in test_list[0].keys()], *[list(idx.values()) for idx in test_list ]] 
print("The converted list : " + str(res)) 



List all Python Programs