1

In python, how do I check if an objects occurs more than 2 times. So basically

test = [object1,object2,object1,object1]
#some stuff
test = [object1]

or

test =[object1,object2,object1,object2,object1,object2]
#some stuff
test =[object1,object2]
greedsin
  • 1,252
  • 1
  • 24
  • 49
  • You may use `Counter()` to get the frequency distribution of each object and then threshold it on frequencies. – ZdaR Jun 23 '17 at 09:23

1 Answers1

3
a = ['a', 'b', 'c', 'a', 'a']
list(set([x for x in a if a.count(x) > 2]))

This returns

['a']

If you need unique values, wrap it in a set.

selten98
  • 821
  • 4
  • 15