On Wed, 2012-01-04 at 15:18 -0800, Brent Lingle wrote:
> why are we putting a 'b' before the 'for' statement. Why not just
> [for b in db.select('bio')]?
>>> [for x in range(20)]
File "<stdin>", line 1
[for x in range(20)]
^
SyntaxError: invalid syntax
We don't do it because we can't. :) The statement
[x for x in some_iterable]
means, "return x for each x in some_iterable". It's not just limited to
"return x". It can be any statement, so you can say "return x+1" or
"return x['some_key']", etc:
[x + 1 for x in some_iterable]
[x['some_key'] for x in some_terable]
You can do awesome things with list comprehensions. You should check out
the docs.
--
Branko Vukelic <[email protected]>
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.