Arithmetic sequences in Python

Gregory Petrosyan gregory.petrosyan at
Mon Jan 16 04:01:39 EST 2006

Please visit first.

As you can see, PEP 204 was rejected, mostly because of not-so-obvious
syntax. But IMO the idea behind this pep is very nice. So, maybe
there's a reason to adopt slightly modified Haskell's syntax? Something

[1,3..10]  -->  [1,3,5,7,9]
(1,3..10)  -->  same values as above, but return generator instead of
[1..10]     -->  [1,2,3,4,5,6,7,8,9,10]
(1 ..)        -->  'infinite' generator that yield 1,2,3 and so on
(-3,-5 ..)   -->  'infinite' generator that yield -3,-5,-7 and so on

1) "[]" means list, "()" means generator
2) the "start" is required, "step" and "end" are optional.

Also, this can be nicely integrated with enumerations (if they will
appear in python). Haskell is also example of such integration.

More information about the Python-list mailing list