This seems like something Python would have a shortcut for. I want to append an item to a list N times, effectively doing this:
l = []
x = 0
for i in range(100):
l.append(x)
It would seem to me that there should be an "optimized" method for that, something like:
l.append_multiple(x, 100)
Is there?
If you want to append elements from another sequence (instead of the same value repeatedly, you can just .extend
with that sequence directly. See How to append to the end of an empty list?.