defaultdict item count 1

defaultdict item count

>>> dict = {'a': 1, 'b': 1, 'c': 3, 'd': 4}
Item Count
>>> len(dict)
4
Count of Items Values
>>> sum(dict.values())
9

Here is what the above code is Doing:
1. We create a dictionary with four items.
2. We print the length of the dictionary.
3. We print the sum of the values in the dictionary.

Similar Posts