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

html - Difficulties with background-image property -

ios - Segue not passing data between ViewControllers -

visual studio code - What does the isShellCommand property actually do and how should you use it? -