import operator str = "abcaaabcccaabrrcb" dict = {ch: str.count(ch) for ch in str} sorted_items = sorted(dict.items(), key=operator.itemgetter(1), reverse=True)
dict((ch, str.count(ch)) for ch in str)