I have
list1 = ["one", "two", "two", "three", "four" , "five", "five", "five", "six"]
and Output should be
list2 = ["five" , "two", "one", "three" , "six"]
"five" is the first element, because list1 has the largest number of entries (3)"two " is the second element, because in list1 there is the next largest number of entries (2)"one" , "three " and "six" have the same fewer occurrences (1), so they are the last in my list2 . In fact, it does not matter in which position they will be like them after the "five" and "two". In short, list2 = ["five" , "two", "six", "three" , "one"] or list2 = ["five" , "two", "three", "one" , "six"] or any other options are accepted.
I could solve this by creating a dictionary to store the number of events, and then create a new list with my items ordered by dict
my_dict = {i:list1.count(i) for i in list1}
but i need something cleaner
source share