I have this code that sorts characters in a string and counts the number of times it's repeated.
def char_repetition(str):
reps = dict()
word = [character.lower() for character in str.split()]
word.sort()
for x in word:
if x in reps:
reps[x] += 1
else:
reps[x] = 1
return reps
for x in char_repetition(str):
print (x,char_repetition(str)[x])
So an input of '1 2 3 2 1 a b c b a'
would yield:
1 2
2 2
3 1
a 2
b 2
c 1
The problem is that I want the numbers to appear at the end of the output like that:
a 2
b 2
c 1
1 2
2 2
3 1