Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
revisited: enumerate is more efficient than list.index solution in Clear category for Sort Array by Element Frequency by juestr
from collections import Counter
def frequency_sort(items):
counts = Counter(items)
order = { k: i for i, k in enumerate(counts) }
return sorted(items, key=lambda x: (-counts[x], order[x]))
May 12, 2019
Comments: