I have a list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] and I want to repeat a list n times.
For example, if n = 2 I want [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9] as output.
Is there any inbuilt solution in python except append and for loop because value of n might go up to 1000 too ?
Python allows multiplication of lists:
my_list = [0,1,2,3,4,5,6,7,8,9]
n = 2
print(my_list*n)
OUTPUT:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
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