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']
![](https://img2018.cnblogs.com/blog/1540240/201910/1540240-20191024215654483-1179296541.png)
![](https://img2018.cnblogs.com/blog/1540240/201910/1540240-20191024215637534-1733395563.png)
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']
![](https://img2018.cnblogs.com/blog/1540240/201910/1540240-20191024215654483-1179296541.png)
![](https://img2018.cnblogs.com/blog/1540240/201910/1540240-20191024215637534-1733395563.png)