Dev Snippets Python
Filtering a list of strings based on contents
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’] Given the list [‘a’,’ab’,’abc’,’bac’], I want to compute a list with strings Read more…