I am trying to find the index of a sub-list return the value with the same index of another sub-list. I keep on running into a problem when I have duplicates, since it just returns the lowest index.
lines = [ [ 1 , 1], [3, 4] ]
x = 0
while x < (len(lines)-1):
for ch in lines[x]:
print lines[x+1][lines[x].index(ch)]
x += 1
I wanted to get an output of
3
4
but I am getting
3
3
lines[1]? For each item inlines[0], you're wanting to find the index of that occurrence of the item (not the first occurrence), and return the corresponding item fromlines[1]. But the sequence of indices that will generate is just 0, 1, 2, ...