Duplicate characters
Write a Python function that returns the characters that appear more than once.
"Programming"
['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"))['g', 'm', 'r']
Learn the concept
New to this topic? Read the lesson, then come back.