Created
June 10, 2021 18:30
-
-
Save landonstewart/647801915aed935c1c6ac6a824af86c2 to your computer and use it in GitHub Desktop.
Return a unique list of elements sorted by frequency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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