For instance, say list L = [0,1,2,3]
and I want to add 10 elements of 4:
L=[0,1,2,3,4,4,4,4,4,4,4,4,4,4]
without needing to use a loop or anything
This is pretty simple thanks to the fact you can add and/or multiply lists:
L += [4] * 10
Here is the proof:
>>> L = [0,1,2,3]
>>> L += [4] * 10
>>> L
[0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
L.extend([4] * 10)
L.extend([some_mutable_object for x in range(10)])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With