list - Python - Repeated (second)) value in tuple -


assuming list follows:

list1 = [('do not care1', 'some string'),     ('do not care1', 'some new string'),     ('do not care2', 'some string'),     ('do not care3', 'some other stringa')     ('do not care4', 'some other stringa')     ('do not care10', 'some other stringb')     ('do not care54', 'some string') 

i need entire entry if second value repeated more 2 times.

in above example, want see output this

'do not care1', 'some string' 'do not care2', 'some string' 'do not care54', 'some string' 

how go doing this?

you can use collections.counter , list comprehension :

>>> form collections import counter >>> [i in list1 if i[1] in [item item,val in counter(zip(*list1)[1]).items() if val>2]] [('do not care1', 'some string'), ('do not care2', 'some string'), ('do not care54', 'some string')] >>>  

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -