Range Operation pre-PEP
aleaxit at yahoo.com
Wed May 9 09:15:54 EDT 2001
"Carlos Ribeiro" <cribeiro at mail.inet.com.br> writes:
> 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.
I think it might be -- I see no graphical suggestion of the
> 2) Force the construct to be specified inside brackets or parenthesis,
> pretty much like list comprehensions.
I like the ideas of brackets for that.
for i in [a:b]
just looks so neat...:-).
> 3) If (2) is approved, then the step operator becomes a natural extension
> of the list comprehension syntax:
> >>> [1..5 step 2]
> >>> [1:5 step 2]
> It's clear, readable and unambiguous.
Sure does. I wonder if 'step' would have to become a keyword here
(presumably a no-go) or if it could be "fudged" the way non-keyword
"as" was added to import and from statements.
More information about the Python-list