﻿ Python: Find the length of a given dictionary values - w3resource

# Python: Find the length of a given dictionary values

## Python dictionary: Exercise-53 with Solution

Write a Python program to find the length of a given dictionary values.

Sample Solution:

Python Code:

``````def test(dictt):
result = {}
for val in dictt.values():
result[val] = len(val)
return result

color_dict = {1 : 'red', 2 : 'green', 3 : 'black', 4 : 'white', 5 : 'black'}
print("\nOriginal Dictionary:")
print(color_dict)
print("Length of dictionary values:")
print(test(color_dict))

color_dict = {'1' : 'Austin Little', '2' : 'Natasha Howard', '3' : 'Alfred Mullins', '4' : 'Jamie Rowe'}
print("\nOriginal Dictionary:")
print(color_dict)
print("Length of dictionary values:")
print(test(color_dict))
```
```

Sample Output:

```Original Dictionary:
{1: 'red', 2: 'green', 3: 'black', 4: 'white', 5: 'black'}
Length of dictionary values:
{'red': 3, 'green': 5, 'black': 5, 'white': 5}

Original Dictionary:
{'1': 'Austin Little', '2': 'Natasha Howard', '3': 'Alfred Mullins', '4': 'Jamie Rowe'}
Length of dictionary values:
{'Austin Little': 13, 'Natasha Howard': 14, 'Alfred Mullins': 14, 'Jamie Rowe': 10}
```

Pictorial Presentation:

Flowchart:

## Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

## Python: Tips of the Day

Invokes the provided function after ms milliseconds:

Example:

```from time import sleep

def tips_delay(fn, ms, *args):
sleep(ms / 1000)
return fn(*args)
print(tips_delay(
lambda x: print(x),
1000,
'w3r'
))
```

Output:

```w3r
None
```