In this python dictionary program, we will find the length of dictionary values.
Steps to solve the program
- Take a dictionary as input and create an empty dictionary.
- Use for loop to iterate over the input dictionary.
- Add the word as key and its length as value to the empty dictionary using the len() function.
- 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}