PEP 276 Simple Iterator for ints (fwd)

Lulu of the Lotus-Eaters mertz at gnosis.cx
Tue Nov 13 16:20:25 CET 2001


David Eppstein wrote:
>    for i in [n-1, n-2, ... 0]:
>        for j in [i+1, i+2, ... n]:
>            ...do something...

James_Althoff at i2.com wrote:
|Thanks for your interesting example.  I agree that your notation "[n-1,
|n-2, ... 0]" is a very nice way of showing a sequence of integers.  I'm not
|sure how one would turn this into programming language syntax that would be
|as clear.

Well... here's how Haskell does it:

  [1 .. 4]         --> [1,2,3,4]
  [4,3 .. 0]       --> [4,3,2,1,0]
  [2,4 .. 10]      --> [2,4,6,8,10]
  [0.0,0.3 .. 1.0] --> [0.0,0.3,0.6,0.9]

It's hard to think of a better syntax for Python to use.




More information about the Python-list mailing list