I have a question, that is, I have 1D list like this:
List_A = []
and I also have another list, something like this:
List_B = [(1,2,3),(2,3,4),(3,4,5)]
Now I try to use:
for i in range(3):
List_A[i] = List_B[i][2]
which means, I want take every last (3rd) number from List_B to List_A, but it is said "index out of range", so what is the problem? Thank you very much for your helping
I know the append method but I think I can't use it, because my code is under a loop, the value in List_B changes in every step,something like:
List_A = []
for i in range(5):
List_B = [(i*1,i*2,i*3),(i*2,i*3,i*4),(i*3,i*4,i*5)]
for j in range(3):
List_A[j] = List_B[j][2]
that is to say, if I use append method, the List_A will enlarge to 15 element size, but I need refresh value in every i loop.
List_A = [3]doesn't create a list with a length of 3, if that's what you think it did. It creates a list with a single element, whose value is 3.