Open ghost opened 8 years ago
"""To find the number of times characters are repeated in a string """
from collections import Counter
Counter('abracadabra').most_common(3)
Counter('abracadabra').most_common(1)
! /usr/bin/env python3
"""To find the number of times characters are repeated in a string """
from collections import Counter
Counter('abracadabra').most_common(3)
[('a', 5), ('r', 2), ('b', 2)]
The argument of most_common is the number of items to be returned
Default will return count for all characters
Counter('abracadabra').most_common(1)
[('a', 5)]