Python Practice › String Programs › Program 76
Characters that occur more than once
Write a Python program to build a string of the characters that occur more than once.
Input
"aabbcceffgh"
Output
abcf
Approach
- Count, then keep characters with a count above 1, in first-seen order.
Solution
from collections import Countertext = "aabbcceffgh"counts = Counter(text)print("".join(ch for ch in counts if counts[ch] > 1))Output
abcf
Learn the concept
New to this topic? Read the lesson, then come back.