There is a question here sort list by frequency
I don't want to bother the collections
library. Here is my solution using 'key' in the sort
S = ['a', 'a', 'b', 'c', 'c', 'c']
S.sort(reverse=True, key=S.count)
or
S.sort(reverse=True, key=lambda x: S.count(x))
But it doesn't work. Any problem with my key
setting?
Thanks