For example, I have:

a = '1' 

How do I find all the items in the list

 lst = ['123' , '231' , '564'] 

who have a mark in themselves

 '1' 
  • In the forehead - go through the list and check for each element there is a sign or not. - Vladimir Martyanov

2 answers 2

 a = '1' lst = ['123' , '231' , '564'] tmp = [item for item in lst if item.find(a) != -1] print(tmp) 

Result ['123', '231']

  • one
    it is better to use a in item (works for any collection), instead of item.find(a) . - jfs
 [item for item in lst if a in item] # or filter(lambda item: a in item, lst) 
  • if you have to use lambda , then most likely you should use an explicit genexp instead of filter() (note filter() does not return a list here). - jfs