Then what about

[x for x in (0, 1, 2, 3, 4, 66, 7, 8, 9, 10)
while x < 10
if x % 2 == 0]

Seems it should be valid and [0, 2, 4].

On Thu, Aug 10, 2017, 14:06 Jussi Piitulainen, <
jussi.piitulai...@helsinki.fi> wrote:

> Steve D'Aprano writes:
>
> > Every few years, the following syntax comes up for discussion, with
> > some people saying it isn't obvious what it would do, and others
> > disagreeing and saying that it is obvious. So I thought I'd do an
> > informal survey.
> >
> > What would you expect this syntax to return?
> >
> > [x + 1 for x in (0, 1, 2, 999, 3, 4) while x < 5]
>
> [1, 2, 3]
>
> > For comparison, what would you expect this to return? (Without
> > actually trying it, thank you.)
> >
> > [x + 1 for x in (0, 1, 2, 999, 3, 4) if x < 5]
>
> [1, 2, 3, 4, 5]
>
> > How about these?
> >
> > [x + y for x in (0, 1, 2, 999, 3, 4) while x < 5 for y in (100, 200)]
>
> [100, 200, 101, 201, 102, 202]
> >
> > [x + y for x in (0, 1, 2, 999, 3, 4) if x < 5 for y in (100, 200)]
>
> [100, 200, 101, 201, 102, 202, 103, 203, 104, 204]
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to