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

Suresh V. suresh_vv at yahoo.com
Fri Mar 31 02:49:04 EDT 2017


On Thursday 30 March 2017 02:48 PM, Markus Meskanen 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? This seems like a rather common
> thing to do, and while the benefit doesn't seem much, something like
> this would be much prettier and more pythonic than using underscore
> variable:
>
> d = [[0] * 5 repeat_for 10]

Why not:

d = [[0] * 5 ] * 10






More information about the Python-ideas mailing list