Duplicate characters

EasyFunction Programs · 23 of 39

Write a Python function that returns the characters that appear more than once.

Advertisement
Input
"Programming"
Output
['g', 'm', 'r']

Approach

  1. Count with Counter and keep counts above 1.

Solution

Python
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']
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More function programs

← All 39 Function Programs