Python program to find the length of dictionary values.

In this python dictionary program, we will find the length of dictionary values.

Steps to solve the program
  1. Take a dictionary as input and create an empty dictionary.
  2. Use for loop to iterate over the input dictionary.
  3. Add the word as key and its length as value to the empty dictionary using the len() function.
  4. Print the output.
				
					D1 = {1:'sql',2:'tools',3:'python'}
D2 = {}

for val in D1.values():
    D2[val] = len(val)
    
print(D2)
				
			

Output :

				
					{'sql': 3, 'tools': 5, 'python': 6}
				
			

extract a list of values from a given list of dictionaries

get the depth of the dictionary.

Leave a Comment