How to get the least common element in a list?

To find the most common, I know I can use something like this:

most_common = collections.Counter(list).most_common(to_find)

However, I can't seem to find anything comparable, for finding the least common element.

Could I please get recommendations on how to do.


Solution 1:

most_common without any argument returns all the entries, ordered from most common to least.

So to find the least common, just start looking at it from the other end.

Solution 2:

What about

least_common = collections.Counter(array).most_common()[-1]