Re:Origins of Python's “Functional” Features (2009)
by teddyh on Monday January 09, 2017 @12:07AM
(#13354141)
First, if your’re only interested in the first value, you should probably use a generator expression instead of a list comprehension, otherwise the loop will run for all mixed_widgets even though they won’t be used:
but this doesn't work, since you can’t do indexing [0] on a generator expression. No matter, next() returns the first value of any iterator:
Also, I think it the repetition of x in the 'x for x in' part is a bit ugly, we can fix that by moving the ['widgets'] attribute retrieval operation to inside the generator expression:
[ Parent
| on HN ]
There are no comments on this comment yet.