I really love pythons possibility to shorten things up with its shorthand for loops — but sometimes, I need to obtain a list containing one value multiple times, which I did the following way:
plot(seconds, [z0 for s in seconds], '--')
But that unused s
really disturbs me for aesthetic reasons.
Is there any shorter (and more beautiful) way of doing so? Like some special “multiplication” of some value?
[1] * 3 -> [1, 1, 1]
. – Busybody_
, unless you can get rid of it – Equatorial_
is for localizing strings... and other times it is a autopopulated context variable provided by the python shell ... – Tradelast__
used as a "junk" variable, specifically to avoid clashing with other uses of single-underscore_
, like the interactive interpreter and thegettext
module. As a bonus, while the leading underscore makes it invisible tofrom <module> import *
, it's not quite long enough to trigger class-private name mangling. – Formative