Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Sort Array by Element Frequency by martin_b
def frequency_sort(items):
# create frequency map, where the value is count of items in integer part
# and position of first appearance in decimal part (it is subtracted so that the ordering is correct)
f = {k: items.count(k) - items.index(k) / len(items) for k in set(items)}
return sorted(items, key=lambda i: -f[i])
Aug. 2, 2019