Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
OrderedDict solution in Clear category for Sort Array by Element Frequency by quarkov
from collections import OrderedDict as odd
def frequency_sort(array):
result, freq_dict = [], odd()
for item in array:
if item not in freq_dict:
freq_dict.update({item: 1})
else:
freq_dict[item] += 1
arranged = [[k]*v for k, v in freq_dict.items()]
for chunk in sorted(arranged, key=len, reverse=True):
result += chunk
return result
Dec. 12, 2018
Comments: