Python Practice › Dictionary Programs › Program 45
Count items in list values
Write a Python program to count the total number of items in all list values.
Input
{"virat": ["match1", "match2", "match3"], "rohit": ["match1", "match2"]}Output
5
Approach
sum(len(v) for v in d.values()).
Solution
d = {"virat": ["match1", "match2", "match3"], "rohit": ["match1", "match2"]}print(sum(len(v) for v in d.values()))Output
5
Learn the concept
New to this topic? Read the lesson, then come back.