
On 3/30/17, Nick Coghlan <ncoghlan@gmail.com> wrote:
On 30 March 2017 at 19:18, Markus Meskanen <markusmeskanen@gmail.com> wrote:
Hi Pythonistas,
yet again today I ended up writing:
d = [[0] * 5 for _ in range(10)]
d = [[0]*5]*10 # what about this?
And wondered, why don't we have a way to repeat other than looping over range() and using a dummy variable?
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.
Cheers, Nick.
Simplified repeating could be probably useful in interactive mode. Just for curiosity - if PEP-501 will be accepted then how many times could be fnc called in next code? eval(i'{fnc()}, ' *3) PL.