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
  • 53
  • 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,253
  • 3
  • 17
  • 48
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
  • 33,938
  • 5
  • 80
  • 91