I am have two lists:
a= [['A', 'B', 'C', 3], ['P', 'Q', 'R', 4]]
b=[['K',1,1,1,1,1], ['L',1,1,1,1,1], ['M', 1,1,0,1,1], ['J', 0,0,0,0,0], ['A', 0,0,0,1,1], ['P',0,1,0,1,1 ]]
I want the output like:
Output=[['A', 0,0,0,1,1], ['P',0,1,0,1,1 ]]
I am trying to search the a in b using the a[idx][0]. Then I want to collect those items and would like the Output something like above.
My code looks like:
Output=[]
for idx in range(len(Test)):
a_idx = [y[0] for y in b].index(a[idx][0])
a_in_b = b[a_idx]
Output.append(a_in_b[:])
print Output
This does not give me the desired output. Can someone please help?
While eumiro’s answer is a better one, you asked for a version which uses index. My version seems to work consistently: