Range Operation pre-PEP
Carlos Ribeiro
cribeiro at mail.inet.com.br
Wed May 9 09:14:08 EDT 2001
At 12:23 09/05/01 +0200, Alex Martelli wrote:
>Getting beginners used to inclusive-upper-end idioms
>and then having them trip over exclusive-upper-end
>ones elsewhere later is NOT doing them any favour.
Ok, I'm in brainstorm mode. You're warned :-) Some weird ideas are just
popping out of my mind:
1) Have both ':' and '..' as range operators. ':' excludes the last
element, '..' includes it. This is a very simple rule-of-thumb. A beginner
may be confused, but it's not something hard to learn.
2) Force the construct to be specified inside brackets or parenthesis,
pretty much like list comprehensions.
3) If (2) is approved, then the step operator becomes a natural extension
of the list comprehension syntax:
>>> [1..5 step 2]
[1,3,5]
>>> [1:5 step 2]
[1,3]
It's clear, readable and unambiguous.
Carlos Ribeiro
More information about the Python-list
mailing list