remove string from list in python

38

>>> l = ['1', '32', '523', '336']
>>> [ x for x in l if "2" not in x ]
['1', '336']
>>> [ x for x in l if "2" in x ]
['32', '523']
strings_with_substring = [string for string in strings if substring in string]

Comments

Submit
0 Comments