"Peter Hansen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> [EMAIL PROTECTED] wrote:
>> Do you think this discussion is a proof that the following principle
>> got violated, or do you think that "loop with condition" is not such an
>> atomic thing to be subject to this: "There sh
[EMAIL PROTECTED] wrote:
> Do you think this discussion is a proof that the following principle
> got violated, or do you think that "loop with condition" is not such an
> atomic thing to be subject to this: "There should be one -- and
> preferably only one -- obvious way to do it."
Mitja's sugges
I think I like generator comprehension in this case better than either
list comprehension or a filter because both of the latter create a new
full "result list" before the loop even begins. At least I suppose they
do. Also, I think Mitja's suggestion "if not : continue" and
Terry's filter function
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>> Why not combine the two:
>
> I guess because (at least in source code) you're doing a loop twice
> :-). I don't know what a compiler would do. I think though that the
> "for i in c if test:" construct is more readable and maybe can ev
Rather than a list comprehension, it would be faster and more
memory-efficient to use a generator comprehension. Just change the
square brackets to parentheses:
for j in (i*2 for i in c if ):
print j
Grant Edwards wrote:
> On 2006-03-26, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrot
> Why not combine the two:
I guess because (at least in source code) you're doing a loop twice
:-). I don't know what a compiler would do. I think though that the
"for i in c if test:" construct is more readable and maybe can even be
better optimized.
Thanks!
Sergey.
--
http://mail.python.org/m
[EMAIL PROTECTED] writes:
> On more than one occasion, I found myself wanting to use a "conditional
> loop" like this (with "Invalid syntax" error, of course):
>
> for i in c if :
> print i*2
>
> ...because it's similar to the list comprehension construct:
>
> [i*2 for i
On 2006-03-26, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I apologize if this was brought up before, I couldn't find any "prior
> art" :-).
> On more than one occasion, I found myself wanting to use a "conditional
> loop" like this (with "Invalid syntax" error, of course):
>
>
Thank you for replying, Mitja! That *is* a nice alternative.
Do you think it's a good idea to ask on comp.python.devel if they would
be interested in a PEP about this (provided there is none)?
Cheers,
Sergey.
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> On more than one occasion, I found myself wanting to use a "conditional
> loop" like this (with "Invalid syntax" error, of course):
>
> for i in c if :
> print i*2
Maybe there's been a PEP, don't really know...
Currently, the only sensible alternati
10 matches
Mail list logo