0

I have a lot of text, and I need to clasify them to find out the number of letters in a joint word. For example:

aabbccccdde

I want it to show a result like:

a 2
b 2
c 4
d 2
e 1

How do I do that?

R2_CoderZ
  • 43
  • 2

2 Answers2

1
word = 'aabbccccdde'
d = {l:word.count(l) for l in set(word)}

for key in sorted(d):
   print(key, d[key])
Suraj
  • 2,059
  • 3
  • 13
  • 38
0

Like this:

from collections import Counter
c = Counter('aabbccccdde')
# c now looks like Counter({'a': 2, 'b': 2, 'c': 4, 'd': 2, 'e': 1})
hd1
  • 32,598
  • 5
  • 75
  • 87