Answer the question
In order to leave comments, you need to log in
Is there a function in Python that finds a different unit of a list?
Given a list, let a = [1, 1, 1, 1, 2, 1, 1, 1]. In this list, all elements are the same, except for one (in this case, 2). The question is, is there such a function in python that finds this very element that is different from the rest?
Answer the question
In order to leave comments, you need to log in
from collections import Counter
rarest = Counter(a).most_common()[-1][0]
rarest = [y for y in list(set(a)) if len([x for x in a if x == y]) == 1][0]
a.sort();
rarest = set(a[:2]) - set(a[-2:])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question