Re: list comprehension



tac-tics wrote:
a wrote:
can someone tell me how to use them
thanks

sigh...
You do a google on them:

http://docs.python.org/tut/node7.html#SECTION007140000000000000000


thank you for the reminder. But after reading it, I was left with a question. Why the new syntax for what appears to be nothing more than a different way of expressing nested for loops? at first I tried rearranging the one of the examples from the previously referenced document to clarify (in my mind) what was going on:

[x*y
for x in vec1
for y in vec2
]

then when I tried to rewrite it as a nested for loop, that's when I realized list comprehensions is a method of returning the calculation in the interior of a for loop as an assignment without requiring aggregation of results in a temporary variable.

so a double thank you to you because you've clarified something that has been a mystery to me for awhile.

now if I could find someone to explain distutils and eggs so that I understand that as well... ;-) Heck, I would even settle for a wizard tool generating the first approximation for me.

---eric

.



Relevant Pages

  • Re: Problem with a script
    ... a loop there becomes impractical. ... You still have them as uniquely named array indexes... ... writing the code twice will only ... reading your entire code and parsing it in their head, ...
    (comp.lang.php)
  • Re: Problem with a script
    ... Okay, so variables have unique labels, that doesn't mean they still couldn't be handled in a loop. ... You still have them as uniquely named array indexes... ... I believe that for the new guy this code would be readable, and identifying problems should really not be any more difficult with this, plus I think that it actually might save some time to write the actual code from the beginnig, even though it's not at it's final stage, instead of first writing everything spread out, and then rewriting the same code again cleaned. ... If you expect a person to spend an hour reading your entire code and parsing it in their head, you wont get any help and have to solve the problem by yourself. ...
    (comp.lang.php)
  • Re: advice and/or help on glReadPixels
    ... I could not see any "BRGA" in the documentation. ... Is it possible that some cards are not ... >>> a) Try reading the entire RGB instead of just the red. ... a quick integer loop with a mask & shift is ...
    (comp.graphics.api.opengl)
  • RE: 2.6.28-rc6-mmotm1126 - acpi AE_AM_INFINITE_LOOP errors..
    ... You could try making the max loop count larger, ... This is a Dell Latitude D820, and didn't seem to have any infinite AML ... reading AC Adapter state ...
    (Linux-Kernel)
  • Re: while (1) vs. for ( ;; )
    ... >to write to the next guy who will be reading the code. ... You are unfamiliar with the term "infinite loop"? ... Balmer Consulting ...
    (comp.lang.c)