Le Friday 05 September 2008 08:30:44 Fredrik Lundh, vous avez écrit :
So do I, most often, but this construct is common, I think because it makes
clear what the for loop is iterating over, also it comes naturally once used
to the more elaborated
for i in (expr(e) for e in iterable if predicate(e)) :
This one is truly a gain for readability IMO, compared to :
for i in iterable:
i = expr(i)
if predicate(i):
In the latter, the reader need more effort to figure out what finally "i" is
in the loop.
and at the cost of an extra indentation level.
--
_____________
Maric Michaud
Maric Michaud wrote:
>
luckily, I don't. most people, when faced with that problem, writes it
in the obvious way:
>
for i in iterable:
if predicate(i):
...
You''ll often see for loops written like this :
for i in (e for e in iterable if predicate(e)) :
...
for i in (e for e in iterable if predicate(e)) :
...
luckily, I don't. most people, when faced with that problem, writes it
in the obvious way:
>
for i in iterable:
if predicate(i):
...
clear what the for loop is iterating over, also it comes naturally once used
to the more elaborated
for i in (expr(e) for e in iterable if predicate(e)) :
This one is truly a gain for readability IMO, compared to :
for i in iterable:
i = expr(i)
if predicate(i):
In the latter, the reader need more effort to figure out what finally "i" is
in the loop.
>
to avoid an extra iterator and save typing.
>
to avoid an extra iterator and save typing.
>
--
_____________
Maric Michaud