How to find tuples from a list of tuples according to specific condition in Python

1 Answer

0 votes
lst_tpl = [('a', 12), ('b', 32), ('c', 17), ('a', 5), ('e', 2), ('f', 43)] 
  
result = [item for item in lst_tpl 
          if item[0] == 'a' or item[1] == 17] 
  
print(result) 



'''
run:

[('a', 12), ('c', 17), ('a', 5)]

'''

 



answered Dec 15, 2019 by avibootz
...