VOOZH about

URL: https://www.geeksforgeeks.org/python/python-convert-list-of-dictionaries-to-list-of-lists/

⇱ Python - Convert List of Dictionaries to List of Lists - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python - Convert List of Dictionaries to List of Lists

Last Updated : 12 Jul, 2025

We are given list of dictionaries we need to convert it to list of lists. For example we are given a list of dictionaries a = [{'name': 'Geeks', 'age': 25}, {'name': 'Geeks', 'age': 30}] we need to convert it in list of list so that the output becomes[['Geeks',25],['Geeks;'30]].

Using List Comprehension

List comprehension iterates over each dictionary in the list, extracting the values of the dictionary. These values are then converted into individual lists and gathered into a new list.


Output
[['Alice', 25], ['Bob', 30]]

Explanation:

  • List comprehension iterates over each dictionary in a, using d.values() to extract the values of each dictionary.
  • These extracted values are then collected into a list, resulting in a new list of lists where each sublist contains the values from a dictionary.

Using map()

Using map() the function can apply the operation of extracting values from each dictionary and converting them into a list.


Output
[['Alice', 25], ['Bob', 30]]

Explanation:

  • map() function applies a lambda to each dictionary in a, using d.values() to extract the dictionary's values.
  • list() function collects the results of map() converting them into a list of lists where each sublist contains the values from a dictionary.

Using itertools.chain()

Using itertools.chain(), we can flatten a list of dictionaries into a single sequence of values.


Output
['Alice', 25, 'Bob', 30]

Explanation:

  • List comprehension is used to iterate over each dictionary in a, extracting its values and converting them into a list.
  • itertools.chain.from_iterable() flattens the list of lists into a single list, combining all the extracted values into one sequence.

Using pandas.DataFrame

Using pandas.DataFrame, the list of dictionaries is converted into a DataFrame, where each dictionary represents a row. Then, df.values.tolist() is used to convert the DataFrame's values into a list of lists.


Output
[['Alice', 25], ['Bob', 30]]

Explanation:

  • List of dictionaries a is converted into a pandas DataFrame, where each dictionary becomes a row.
  • .values.tolist() method is used to convert the DataFrame's values into a list of lists, where each sublist represents a row's values.
Comment