Python Practice › Function Programs › Program 23
Duplicate characters
Write a Python function that returns the characters that appear more than once.
Input
"Programming"
Output
['g', 'm', 'r']
Approach
- Count with
Counterand keep counts above 1.
Solution
from collections import Counter def duplicates(text): counts = Counter(text.lower()) return sorted(ch for ch, n in counts.items() if n > 1) print(duplicates("Programming"))Output
['g', 'm', 'r']
Learn the concept
New to this topic? Read the lesson, then come back.