removing all instances of a certain value from a list

Hrvoje Niksic hniksic at xemacs.org
Wed Mar 19 23:41:12 CET 2008


Lee Sander <lesande at gmail.com> writes:

> Hi,
> I have a float array ( eg [-1.3, 1.22, 9.2, None, 2.3] ) but there are
> many missing vlaues which are represented as None. I would like to
> remove all such instances in one go.
> There is a remove function but it removes only the first instance, is
> there a delete/remove all function?

No, but you can easily simulate it using, for example:

lst[:] = (el for el in lst if el is not None)



More information about the Python-list mailing list