Proposed new syntax

Paul Rubin no.email at nospam.invalid
Fri Aug 11 04:01:52 EDT 2017


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] though the later example is more confusing.

I don't think we need this since we have itertools.takewhile:

  from operator import gt
  from functools import partial
  from itertools import takewhile

  [x + 1 for x in takewhile(partial(gt,5), (0,1,2,999,3,4))]

In the eye of the beholder maybe, but I think it's less ugly in Haskell:

  [x + 1 | x <- takeWhile (< 5) [0,1,2,999,3,4]]



More information about the Python-list mailing list