I have a list, and I want to repeat its elements in the same order.
I want to create bg using sl.
# small list
sl = [10,20]
# from small list, create a big list
bg = [10,10,20,20]
I tried:
bg = [[i,j] in for i,j in zip([[sl[0]]*2,[sl[1]]*2])]
But this gives me:
bg = [[10,20],[10,20]]
How can I get the desired output?
>Solution :
import numpy as np
s1 = [10,20]
s2 = np.array(s1).repeat(2)
print(list(s2)) # [10, 10, 20, 20]
I could not resist the urge to use numpy in such operations. With this function you can repeat not only for single dimensional cases but also in case of matrix or higher order tensors as well.