S = "aaabcdbbdcccf" lst = sorted(S, key=lambda x: S.count(x), reverse=True) lst
输出:['c', 'c', 'c', 'c', 'a', 'a', 'a', 'b', 'b', 'b', 'd', 'd', 'f']