Convert List of Lists to Dictionary - Python Last Updated : 21 Jan, 2025 Comments Improve Suggest changes Like Article Like Report We are given list of lists we need to convert it to python . For example we are given a list of lists a = [["a", 1], ["b", 2], ["c", 3]] we need to convert the list in dictionary so that the output becomes {'a': 1, 'b': 2, 'c': 3}. Using Dictionary ComprehensionUsing dictionary comprehension, we iterate over each sublist in the list of lists, unpacking the first element as the key and the second as the value. This creates a dictionary efficiently in a single line of code. Python # List of lists where each sublist contains a key-value pair a = [["a", 1], ["b", 2], ["c", 3]] # Use dictionary comprehension to create a dictionary # Unpack each sublist into key and value, and map them to the dictionary res = {key: value for key, value in a} print(res) Output{'a': 1, 'b': 2, 'c': 3} Explanation:Dictionary comprehension iterates through each sublist in a, unpacking the first element as the key and the second as the value.It constructs a dictionary by mapping each key to its corresponding value, resulting in {'a': 1, 'b': 2, 'c': 3}.Using dict()To convert a list of lists into a dictionary using dict(), we can pass the list of lists to the dict() constructor. Python # List of lists where each sublist contains a key-value pair a = [["a", 1], ["b", 2], ["c", 3]] # Convert the list of lists into a dictionary using the dict() function # Each sublist is unpacked into key and value pairs res = dict(a) print(res) Output{'a': 1, 'b': 2, 'c': 3} Explanation:Code converts a list of lists into a dictionary using the dict() function, where each sublist represents a key-value pair.dict() function takes the list of lists as an argument and returns a dictionary with keys "a", "b", and "c", and their respective values 1, 2, and 3.Using zip()We can use the zip() function to pair corresponding elements from two lists, creating an iterable of tuples. By passing this result to the dict() function, we can easily convert it into a dictionary, where the first list becomes the keys and the second list becomes the values. Python keys = ["a", "b", "c"] values = [1, 2, 3] # Use the zip() function to pair keys with values, then convert the result into a dictionary using dict() res = dict(zip(keys, values)) print(res) Output{'a': 1, 'b': 2, 'c': 3} Explanation:zip() function combines the keys and values lists by pairing corresponding elements together, creating tuples like ("a", 1), ("b", 2), and ("c", 3).dict() function then converts these pairs into a dictionary, resulting in {'a': 1, 'b': 2, 'c': 3}. Comment More infoAdvertise with us Next Article Convert List of Lists to Dictionary - Python manjeet_04 Follow Improve Article Tags : Python Python Programs Python list-programs Python dictionary-programs Practice Tags : python Similar Reads Python - Convert List to List of dictionaries We are given a lists with key and value pair we need to convert the lists to List of dictionaries. For example we are given two list a=["name", "age", "city"] and b=[["Geeks", 25, "New York"], ["Geeks", 30, "Los Angeles"], ["Geeks", 22, "Chicago"]] we need to convert these keys and values list into 4 min read Convert List of Dictionary to Tuple list Python Given a list of dictionaries, write a Python code to convert the list of dictionaries into a list of tuples.Examples: Input: [{'a':[1, 2, 3], 'b':[4, 5, 6]}, {'c':[7, 8, 9], 'd':[10, 11, 12]}] Output: [('b', 4, 5, 6), ('a', 1, 2, 3), ('d', 10, 11, 12), ('c', 7, 8, 9)] Below are various methods to co 5 min read Python - Convert List of Dictionaries to List of Lists 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 Comprehens 3 min read Convert List of Tuples to Dictionary Value Lists - Python The task is to convert a list of tuples into a dictionary where the first element of each tuple serves as the key and the second element becomes the value. If a key appears multiple times in the list, its values should be grouped together in a list.For example, given the list li = [(1, 'gfg'), (1, ' 4 min read Convert List Of Dictionary into String - Python In Python, lists can contain multiple dictionaries, each holding key-value pairs. Sometimes, we need to convert a list of dictionaries into a single string. For example, given a list of dictionaries [{âaâ: 1, âbâ: 2}, {âcâ: 3, âdâ: 4}], we may want to convert it into a string that combines the conte 3 min read Like