iterating through lists to delete elements

Patrick Vrijlandt p.vrijlandt at aig.azn.nl
Thu Aug 9 12:00:36 EDT 2001


> Can anyone advise me the best way to iterate through a list and deleting
> elements that don't meet a certain criteria.

Maybe you can use filter
>>> lst = [1, 2, 3, 4]
>>> filter(lambda x: x >= 3, lst)
[3, 4]

Or you can use a list comprehension:
>>> [x for x in lst if x >= 3 ]
[3, 4]

--
Patrick Vrijlandt





More information about the Python-list mailing list