-1

How can you count the characters (characters frequency) in a string without using if, while or for?

Blue
  • 11

1 Answers1

0

You can use Counter, it returns a dictionary with character as a key and its frequency as its value.

from collections import Counter
x = "abcdasbdd"
print(Counter(x))

Output

Counter({'d': 3, 'a': 2, 'b': 2, 'c': 1, 's': 1})
Cute Panda
  • 1,468
  • 1
  • 6
  • 11