VOOZH about

URL: https://www.geeksforgeeks.org/python/python-convert-key-value-list-dictionary-to-list-of-lists/

⇱ Python - Convert Key-Value list Dictionary to List of Lists - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python - Convert Key-Value list Dictionary to List of Lists

Last Updated : 12 Jul, 2025

We are given a key value list dictionary we need to convert it list of lists. For example we are given a dictionary a = {'name': 'Geeks', 'age': 8, 'city': 'Noida'} we need to convert this into list of lists so the output should be [['name', 'Geeks'], ['age', 25], ['city', 'Geeks']].

Using List Comprehension

List comprehension iterates over each key-value pair in the dictionary, extracting both the key and its corresponding value. These pairs are then collected into sublists, resulting in a list of lists.


Output
[['name', 'Alice'], ['age', 25], ['city', 'New York']]

Explanation:

  • List comprehension iterates over the key-value pairs in the dictionary a using .items().
  • For each key-value pair, a sublist [key, value] is created, resulting in a list of lists.

Using map()

map()function applies a lambda to each key-value pair in the dictionary, converting each pair into a list. The result is then converted to a list, creating a list of lists with key-value pairs.


Output
[['name', 'Alice'], ['age', 25], ['city', 'New York']]

Explanation:

  • map() function iterates over each key-value pair in the dictionary a, transforming each pair into a list containing the key and the corresponding value ([item[0], item[1]]).
  • list() function converts the result from map() (an iterable) into a list of lists, which is then printed as the final output

Using dict.items() and list()

dict.items() method provides the dictionary's key-value pairs as tuples. Using list(), these pairs are converted into a list of lists, where each list contains a key-value pair.


Output
[['name', 'Alice'], ['age', 25], ['city', 'New York']]

Explanation:

  • map(list, a.items()) applies the list() function to each key-value pair (tuple) from the dictionary a, converting each tuple into a list of the form [key, value].
  • list() function collects the results from map() into a list of lists, which is then printed as the final output.
Comment