Reputation: 89
Is there a quicker way to write .append more than once? Like:
combo.append(x) * 2
Instead of:
combo.append(x)
combo.append(x)
I know you cant multiply it by 2, so I'm wondering if there is a faster way?
Upvotes: 0
Views: 285
Reputation: 8781
You might try something like combo.extend([x]*t)
to append t
copies of x.
Upvotes: 1
Reputation: 1123440
You can extend instead of append:
combo.extend([x] * 2)
If combo
is a local or a global, you can also use +=
to extend a list:
combo += [x] * 2
If combo
is an class attribute, just be careful if you are referencing it on an instance, see Why does += behave unexpectedly on lists?
Upvotes: 1