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

Nick Timkovich prometheus235 at gmail.com
Tue Feb 14 17:19:57 EST 2017


for i in range(...) is *sometimes* indicative of code smell, especially
when then doing x[i], though it has its uses. I've never had a need to
shorten a for...range line though.

Other than it being "cute", do you have an example where it's definitively
better?

On Tue, Feb 14, 2017 at 4:03 PM, Todd <toddrjen at gmail.com> wrote:

> On Tue, Feb 14, 2017 at 4:41 PM, MRAB <python at mrabarnett.plus.com> wrote:
>
>> On 2017-02-14 21:09, Zachary Ware wrote:
>>
>>> 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)
>>>>
>>>
>>> This is already valid and useful syntax, and thus a non-starter.
>>>
>>>    >>> for x in 0,5 :
>>>    ...     print (x)
>>>    ...     for y in 0,10,2 :
>>>    ...         print (y)
>>>    ...         for z in 0, y+8 :
>>>    ...             print (z)
>>>    ...
>>>    0
>>>    0
>>>    0
>>>    8
>>>    10
>>>    0
>>>    18
>>>    2
>>>    0
>>>    10
>>>    5
>>>    0
>>>    0
>>>    8
>>>    10
>>>    0
>>>    18
>>>    2
>>>    0
>>>    10
>>>
>>> The closest you could get without breaking existing code is [a:b:c]:
>>
>> for x in [0:5]:
>>     print(x)
>>     for y in [0:10:2]:
>>         print(y)
>>         for z in [0:y+8]:
>>             print(z)
>>
>> What's more, that could be valid outside the 'for' loop too.
>>
>>
> Guido has already rejected this syntax and several others.
>
> _______________________________________________
> 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/1411237d/attachment.html>


More information about the Python-ideas mailing list