Is it possible in python to count letters and sort by character in string occurrence?
For example,
string = "Johnyjohny"
output:
{'J': 1, 'o': 2, 'h': 2, 'n': 2, 'y': 2, 'j': 1}
I can count it or sort it in alphabetical order.
def dictcode(str=""):
str = "Johnyjohny"
dict1 = dict((letter,str.count(letter)) for letter in set(str))
return dict1
print(dictcode())