[Python-ideas] iterator length

Rob Cliffe rob.cliffe at btinternet.com
Tue Aug 10 18:55:28 CEST 2010


It seems to me that, to count the not-None elements, your logic is inverted.
Surely you want
    sum(1 for e in iterator if e)
or more accurately
    sum(1 for e in iterator if e is not None)
Rob Cliffe

----- Original Message ----- 
From: "Alexandru Moșoi" <brtzsnr at gmail.com>
To: "Scott Dial" <scott+python-ideas at scottdial.com>
Cc: <python-ideas at python.org>
Sent: Tuesday, August 10, 2010 5:45 PM
Subject: Re: [Python-ideas] iterator length


> 2010/8/10 Scott Dial <scott+python-ideas at scottdial.com>:
>> You are responding to his request for a specific example with a generic
>> class of examples, which is what prompted his request for a specific
>> example in the first place. Please give a *specific* example and be
>> prepared to be told that you are going about it the wrong way, since, at
>> this point, nobody has replied as having recognized this as a problem
>> they've encountered before.
>
> My exact need is to count the not-None elements in a list. My current
> solution is, as described before:
>    sum(1 for e in iterator if not e)
>
>
> -- 
> Alexandru Moșoi
> http://www.alexandru.mosoi.ro/
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
> 




More information about the Python-ideas mailing list