Count items in list values

EasyDictionary Programs · 45 of 94

Write a Python program to count the total number of items in all list values.

Advertisement
Input
{"virat": ["match1", "match2", "match3"], "rohit": ["match1", "match2"]}
Output
5

Approach

  1. sum(len(v) for v in d.values()).

Solution

Python
d = {"virat": ["match1", "match2", "match3"], "rohit": ["match1", "match2"]}print(sum(len(v) for v in d.values()))
Output
5
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs