removing all instances of a certain value from a list

r.grimm at science-computing.de r.grimm at science-computing.de
Fri Mar 21 04:53:23 EDT 2008


On Mar 19, 11:28 pm, Lee Sander <lesa... at gmail.com> wrote:
> 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?
> thanks
You can also do it with the filter function.
>>> a= [-1.3, 1.22, 9.2, None, 2.3]
>>> a=filter ( lambda b: b != None, a)
>>> print a
[-1.3, 1.22, 9.1999999999999993, 2.2999999999999998]

Greetings Rainer



More information about the Python-list mailing list