Arithmetic sequences in Python

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


Please visit http://www.python.org/peps/pep-0204.html 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
like

[1,3..10]  -->  [1,3,5,7,9]
(1,3..10)  -->  same values as above, but return generator instead of
list
[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

So,
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