Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save landonstewart/647801915aed935c1c6ac6a824af86c2 to your computer and use it in GitHub Desktop.
Save landonstewart/647801915aed935c1c6ac6a824af86c2 to your computer and use it in GitHub Desktop.
Return a unique list of elements sorted by frequency
from collections import Counter
def unique_list(*args):
counted = Counter(args[0])
return [value for value, count in counted.most_common()]
Example:
>>> unique_list([1,2,3,4,5,6,6,6,5,4,4])
[4, 6, 5, 1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment