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

Kyle Lahnakoski klahnakoski at mozilla.com
Thu Mar 30 11:06:21 EDT 2017



On 2017-03-30 05:18, Markus Meskanen wrote:
> Hi Pythonistas,
>
> yet again today I ended up writing:
>
> d = [[0] * 5 for _ in range(10)]
>
>
> Thoughts?

It looks like you are initializing matrices.  Can you make a helper
function?

d = matrix(shape=(5, 10), default=0)

or maybe use NumPy?


More information about the Python-ideas mailing list