Python Practice › String Programs › Program 55
Find duplicate characters
Write a Python program to find the characters that appear more than once (ignoring spaces).
Input
"hello world"
Output
lo
Approach
- Count characters and keep those with a count above 1.
Solution
from collections import Counter text = "hello world"counts = Counter(text.replace(" ", ""))print("".join(ch for ch, n in counts.items() if n > 1))Output
lo
Learn the concept
New to this topic? Read the lesson, then come back.