Removing None objects from a sequence

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Dec 12 11:13:56 EST 2008


On Fri, 12 Dec 2008 16:51:15 +0100, Marco Mariani wrote:

> Filip Gruszczyński wrote:
> 
> 
>> I am not doing it, because I need it. I can as well use "if not elem is
>> None",
> 
> I suggest "if elem is not None", which is not quite the same.

In which way is it not the same?  Has the same behavior at least:

In [256]: elem = None

In [257]: not elem is None
Out[257]: False

In [258]: elem is not None
Out[258]: False

In [259]: elem = 42

In [260]: not elem is None
Out[260]: True

In [261]: elem is not None
Out[261]: True

> If you slip such an error in a post, I suggest to practice some time
> writing correct code before having one-liner contests with your
> perl-loving friends :)

If you call something an error, make sure it really is one.  :-)

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list