Python Practice › Dictionary Programs › Program 76
Total length of string keys
Write a Python program to count the number of keys and the total characters in them.
Input
{"virat": 50, "Rohit": 40, "Rahul": 25}Output
Keys: 3 Total length of keys: 15
Approach
len(d)for keys,sum(len(k) ...)for characters.
Solution
d = {"virat": 50, "Rohit": 40, "Rahul": 25}print("Keys:", len(d))print("Total length of keys:", sum(len(k) for k in d))Output
Keys: 3 Total length of keys: 15
Learn the concept
New to this topic? Read the lesson, then come back.