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' 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' a = '1' lst = ['123' , '231' , '564'] tmp = [item for item in lst if item.find(a) != -1] print(tmp) Result ['123', '231']
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) lambda , then most likely you should use an explicit genexp instead of filter() (note filter() does not return a list here). - jfsSource: https://ru.stackoverflow.com/questions/592782/
All Articles