451. 根据字符出现频率排序
class Solution(object):
def frequencySort(self, s):
"""
:type s: str
:rtype: str
"""
mydict = {}
for item in s:
if item in mydict.keys():
mydict[item] += 1
else:
mydict[item] = 1
newlist = sorted(mydict.items(), key=lambda x: x[1], reverse=True)
res = ""
for i in newlist:
res += "".join(i[0] * i[1])
return res