Last modified: Jan 11, 2023 By Alexander Williams

Python dictionary: Count values per key

In this tutorial, we going to learn how to get the length of the dictionary per key using len() built function

1. What is len() ?

Len() is a Python built function, that returns the number of items of an object.

2. Syntax


len(your_dictionary)

3. Example: Getting the length of a dictionary

In the following example, we'll count the values of a dictionary per key.


#dictionary
dictionary1 = {'name':'cat', 'age':'22', 'nationality':'MA'}

#Return the number of items dictionary:
print(len(dictionary1))

output

3

4. Summary

In this article, we've learned how to get the length of a dictionary by using Len() built-function, you can also use this Len() with a tuple, list, and string.