[Python-ideas] Way to repeat other than "for _ in range(x)"

Allan Clark allan.clark at gmail.com
Thu Mar 30 06:24:52 EDT 2017


If there were to be special syntax for this case, I'd just allow an
empty pattern, such as:

    d = [[0] * 5 for in 10]

This is exactly the same as your 'repeat_for' except that it is spelt
'for in', which means there are no new keywords. It would also be
allowed in for-loops in the same way as your example. I believe this
would even be relatively simple to implement (but don't know).
But I'm afraid, I'd be -1 on this, two reasons:

1. Subjective it may be, but my subjective opinion is that this does
not come up often enough to warrant this change.
2. When it does come up for those learning the language, they learn a
useful idiom of using '_' or '__' for variables that you intend not be
used.

Thanks,
Allan.



On 30 March 2017 at 10:59, Markus Meskanen <markusmeskanen at gmail.com> wrote:
>
>
> On Thu, Mar 30, 2017 at 12:53 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>
>> Because it's relatively rare to not use the loop variable for anything
>> (even if it's just a debug message), and in the cases where you
>> genuinely don't use it, a standard idiom can be applied (using a
>> single or double underscore as a dummy variable), rather than all
>> future users of the language needing to learn a special case syntax.
>
>
> I think "relatively rare" is rather subjective, it's surely not everyday
> stuff but that doesn't mean it's not done often.
> And instead of learning a special syntax, which is simple and easy to
> understand when they google "repeat many times python", they now end up
> learning a special semantic by naming the variable with an underscore. If
> and when someone asks "how to repeat many times in Python", I'd rather
> answer "use repeat_for X" instead of "use for _ in range(X)"
>
> _______________________________________________
> 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/
>


More information about the Python-ideas mailing list