[Python-ideas] Contraction for "for x in range()"

Mikhail V mikhailwas at gmail.com
Tue Feb 14 19:20:37 EST 2017

On 15 February 2017 at 00:41, Nick Timkovich <prometheus235 at gmail.com>

> Make some shim object that you can index into to get that functionality,
> could even call it Z (for the set of all integers). Short, and requires no
> new syntax.
> class IndexableRange:
>     def __getitem__(self, item):
>         if isinstance(item, slice):
>             start = item.start if item.start is not None else 0
>             step = item.step if item.step is not None else 1
>             if item.stop is None:
>                 return itertools.count(start, step)
>             else:
>                 return range(start, item.stop, step)
>         else:
>             return item
> Z = IndexableRange()
> for y in Z[0:10:2]:
>     print(y)
l can, also just make function r(a,b,c) : return range(a,b,c) for example,
will look similar.
Initially I was by the idea to remove brackets from for statement.
Now after looking more at examples I realize what the real
issue with the look is. Namely it is the word "in" itself. It is simply too
and that makes a lot of space holes in the lines.
And letters 'i' and 'n' sort of suck from readability POV.

E.g. compare:

for x in 1,10,2:


for x over 1,10,2 :

So the latter actually would make it look nicer.
But that would probably be even less probable to
be implemented.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170215/75f6eb30/attachment.html>

More information about the Python-ideas mailing list