Nov-25-2020, 08:47 AM
to get character count:
from collections import Counter def CharacterCount(S): S = S.strip().replace(' ','') return Counter(S) print(f"\nCounts 'Python is great fun': {CharacterCount('Python is great fun')}") print(f"Counts 'Good Times': {CharacterCount('Good Times')}\n")
Output:Counts 'Python is great fun': Counter({'t': 2, 'n': 2, 'P': 1, 'y': 1, 'h': 1, 'o': 1, 'i': 1, 's': 1, 'g': 1, 'r': 1, 'e': 1, 'a': 1, 'f': 1, 'u': 1})
Counts 'Good Times': Counter({'o': 2, 'G': 1, 'd': 1, 'T': 1, 'i': 1, 'm': 1, 'e': 1, 's': 1})