Convert a list into a nested dictionary of keys.

In this python dictionary program, we will convert a list into a nested dictionary of keys.

Steps to solve the program
  1. Take a list of characters as input and create two empty dictionaries.
  2. Use for loop to iterate over characters in the list.
  3. Add the character as the key and an empty dictionary as its value.
  4. Now add the above key to the empty dictionary.
  5. Print the output.
				
					list1 = ['a','b','c','d']
new_dict = current = {}

for char in list1:
    current[char] = {}
    current = current[char]
print(new_dict)
				
			

Output :

				
					{'a': {'b': {'c': {'d': {}}}}}
				
			

find mean of values of keys in a dictionary.

sort a list of values in a dictionary.

Leave a Comment