arr = [] for i in set(list(str)): arr.append((i, str.count(i))) sort_arr = (sorted(arr, key = lambda x:x[1], reverse = True)) for t in sort_arr: word, count = t[0], t[1]
string = input('Enter string :') while string != '#': s=list(string) s.sort() s.reverse() temp=[] for t in s: if t not in temp: temp.append(t) for word in temp: count = s.count(word) print('{0:<10}{1:>5}'.format(word,count)) string = input('Enter string :')