I want to repeat the line A=A[:1] + [i + 1 for i in A] several times based on the length of B. For instance, len(B)=4 and A=A[:1] + [i + 1 for i in A] has been repeated 4 times. Is there a way to repeat A=A[:1] + [i + 1 for i in A] without writing it explicitly and get the same current output?
A=[0,1,2,3,4,5,6,7]
B=[1,3,6,7]
A=A[:1] + [i + 1 for i in A]
A=A[:1] + [i + 1 for i in A]
A=A[:1] + [i + 1 for i in A]
A=A[:1] + [i + 1 for i in A]
print(A)
The current output is
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
>Solution :
Try this:
for j in range(len(B)):
A = A[:1] + [i + 1 for i in A]
Then just print normally after the for loop.