Removing None objects from a sequence

J. Cliff Dyer jcd at sdf.lonestar.org
Mon Dec 15 16:58:57 EST 2008


On Mon, 2008-12-15 at 02:11 +0000, Lie Ryan wrote:
> On Fri, 12 Dec 2008 22:55:20 +0000, Steven D'Aprano wrote:
> 
> > On Fri, 12 Dec 2008 21:18:36 +0000, Lie Ryan wrote:
> >> Personally, I'd prefer VB's version:
> >> foo IsNot bar
> >> 
> >> or in pseudo-python
> >> foo isnot bar
> >> 
> >> since that would make it less ambiguous.
> > 
> > "a is not b" is no more ambiguous than "1+2*3". True, there's ambiguity
> > if you are ignorant of the precedence rules, but that's no worse than
> > saying that "+" is ambiguous if you don't know what "+" means.
> > 
> > "What's this 'is' operator??? It's ambiguous, it could mean ANYTHING!!!
> > Panic panic panic panic!!!"
> > 
> > *wink*
> > 
> > You're allowed to assume the normal conventions, and (lucky for me!)
> > despite being Dutch Guido choose to assume the normal English convention
> > that "a is not b" means the same as "not (a is b)" rather than "a is
> > (not b)". That's probably because the use-cases for the second would be
> > rather rare.
> > 
> > So given the normal precedence rules of Python, there is no ambiguity.
> > True, you have to learn the rules, but that's no hardship.
> 
> *I* know about the precedence rule, but a newbie or a tired programmer 
> might not. He might want to reverse the truth value of argument b but 
> instead has just reversed the whole expression. Probably in a slightly 
> convoluted code like this:
> 
> if a is not(b and c): 
>    ...
> 

A newbie might make that mistake, but a tired programmer would be
testing for equality rather than identity in that case, and if she
weren't, she'd have to fix her code in the morning anyway.

Cheers,
Cliff





More information about the Python-list mailing list