String characters | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

String characters

i need help with finding how to find how many characters are in the string for example. input is Hello output to be H,1 e,1 l,2 o,1

4th Nov 2016, 3:01 AM
alex slater
alex slater - avatar
1 Answer
0
you will need to create a dictionary, store characters as keys and their amount in string as values str = 'example string' stat = dict() for char in str: if char in stat: stat[char] += 1 else stat[char] = 1 print (stat)
4th Nov 2016, 4:55 AM
Demeth
Demeth - avatar