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

Abe Dillon abedillon at gmail.com
Tue Feb 14 16:25:23 EST 2017

I would be surprised if this hasn't been suggested many times before. It's
similar to Matlab's syntax:

for x = start:step:finish
    <do whatever>

Any such change would represent a large departure from normal python syntax
for dubious gain. In general, you can put any expression after the `in`
keyword so long as it evaluates to an iterable or an iterator. Your
specific proposal would break some perfectly valid code.

You could likely come up with some symbols that couldn't show up in
existing code, but it's usually better to use words instead of obscure
symbol notation to preserve the readability of Python rather than letting
it devolve into a concise, yet unreadable soup of symbols like Perl.

On Tue, Feb 14, 2017 at 3:06 PM, Mikhail V <mikhailwas at gmail.com> wrote:

> I have a small syntax idea.
> In short, contraction of
> for x in range(a,b,c) :
> to
> for x in a,b,c :
> I really think there is something cute in it.
> So like a shortcut for range() which works only in for-in statement.
> So from syntactical POV, do you find it nice syntax?
> Visually it seems to me less bulky than range().
> Example:
> for x in 0,5 :
>     print (x)
>     for y in 0,10,2 :
>         print (y)
>         for z in 0, y+8 :
>             print (z)
> Which would be short for:
> for x in range(0,5):
>     print (x)
>     for y in range(0,10,2):
>         print (y)
>         for z in range(0, y+8):
>             print (z)
> Mikhail
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170214/dbfabbb6/attachment.html>

More information about the Python-ideas mailing list