Elegant way to remove items from sequence in Python? [duplicate]
Two easy ways to accomplish just the filtering are: Using filter: names = filter(lambda name: name[-5:] != “Smith”, names) Using list comprehensions: names = [name for name in names if name[-5:] != “Smith”] Note that both cases keep the values for which the predicate function evaluates to True, so you have to reverse the logic … Read more