
March 30, 2017
9:53 a.m.
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)]
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. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia