double sorting. first by index, then by count solution in Uncategorized category for Sort Array by Element Frequency by kaisa.kucherenko
""" First sort by list.index() using lambda.
Then, once again, we sort already by list.count(), also using lambda
The first sorting by index is needed for the case when there are
several elements with the same list.count()
return sorted(sorted(items, key=lambda item: items.index(item)), key=lambda item: items.count(item), reverse=True)
May 27, 2020