|
![](/i/fill.gif) |
On 8/17/2011 7:45 PM, Darren New wrote:
> Hmm.
>
> y = (x for x in List)
> if some_funk(y) or some_other_func(y) and a_third_func(y):
>
> Why would you even want to calculate (x for x in List) three times?
>
> Or am I misunderstanding "x for x in List"? Isn't that a list
> comprehension in Python?
>
It's not a list comprehension, but rather creates a generator object
iterating over the items in List. The list comprehension would use
square brackets [x for x in List]. I still don't understand why it's
being used here though, since it seems like List could just be passed in
directly since it's obviously iterable too (unless the called functions
are doing something odd, which maybe is the case here).
Post a reply to this message
|
![](/i/fill.gif) |