Convert a list of Tuples into a dictionary

In this python dictionary program, we will convert a list of Tuples into a dictionary

Steps to solve the program
  1. Take a list of tuples as input and create an empty list.
  2. Use for loop to iterate over a list of tuples.
  3. From tuples add 1st element as the key and 2nd element as its value to the dictionary.
  4. Print the output.
				
					list1 = [("mike",1),("sarah",20),("jim", 16)]
dict1 = {}
for val in list1:
    dict1[val[0]] = val[1]
    
print(dict1)
				
			

Output :

				
					{'mike': 1, 'sarah': 20, 'jim': 16}
				
			

convert a key-values list to a flat dictionary.

convert string to the dictionary.

Leave a Comment