This simple filtering can be achieved in many ways using Python. The best approach is to use list comprehension as follows:
>>> lst = ['a', 'ab', 'abc', 'bac'] >>> res = [k for k in lst if 'ab' in k] >>> res ['ab', 'abc'] >>>
Another way is to use the filter function:
>>> filter(lambda k: 'ab' in k, lst) ['ab', 'abc'] >>>
Eli Bendersky Jan 28 '10 at 7:20 2010-01-28 07:20
source share