I need to receive a string from the user, present it in list so each organ in the list contains [the letter, the number it repeat in a row].
I thought my code is goo
You can do this very easily using defaultdict:
import collections
defaultdict=collections.defaultdict
count=defaultdict(int)
string="hello world"
for x in string:
count[x]+=1
To show it in a list you can do:
count.items()
which in this case would return:
[(' ', 1), ('e', 1), ('d', 1), ('h', 1), ('l', 3), ('o', 2), ('r', 1), ('w', 1)]