Proposed new syntax

John Gordon gordon at panix.com
Thu Aug 10 13:48:33 EDT 2017


In <598c6d74$0$1588$c3e8da3$5496439d at news.astraweb.com> Steve D'Aprano <steve+python at pearwood.info> writes:

> 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, 101, 102, 200, 201, 202]

> [x + y for x in (0, 1, 2, 999, 3, 4) if x < 5 for y in (100, 200)]

[100, 101, 102, 103, 104, 200, 201, 202, 203, 204]

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list