On 04/27/12 07:23, Chris Angelico wrote:
On Fri, Apr 27, 2012 at 10:17 PM, John O'Hagan<resea...@johnohagan.com> wrote:
results = [x = expensive_call(i) for i in iterable if condition(x)]
Nest it:
results = [x for x in (expensive_call(i) for i in iterable) if condition(x)]
While it's what I do in cases like this, the nesting is not
nearly as readable as John's suggested syntax. Granted, the
ability to do assignments in such a context opens up a whole can
of unpythonic worms, so I'd suggest the following for clarity:
temp = (expensive_call(i) for i in iterable)
results = [x for x in temp if condition(x)]
-tkc
--
http://mail.python.org/mailman/listinfo/python-list