arranging numbers when max count has equal occurances

2 days ago 11
ARTICLE AD BOX

I have a list (my_list), and i arranged the list according to most common occurance.

my_list = [1,3,3,5,5,2,1,1] #arrage according to most common occurances from collections import Counter a=([k for k, s in Counter(my_list).most_common()]) print(a)

And the output is [1, 3, 5, 2].

Even though both 3 and 5 has double numbers in the list, but it came numerically . First 3, then 5. Is there a way, where a value i provide will be at the front when there's equal occurance. For example i provide a variable number = 5, and in the output list 5 will come before 3?

Read Entire Article