1
votes

I have 2 lists of lists and I want to filter list1 based on matching with elements in list2:

list1 = [[1,2,3], [4,5,3]]
list2 = [[9,8,3], [7,10,6]]

I want to get the elements from list1 (list) that have the same last element in elements(which have the same position) in list2

In my example

list1[0][-1] is similar to list2[0][-1]

I want to compare only lists on the same position; means list1[0] vs list2[0] and list1[1] vs list2[1] and list1[2] vs list2[2] and so on (only lists with the same position)

1

1 Answers

2
votes

try this,

print([x for x, y in zip(list1, list2) if x[-1] == y[-1]])

[[1, 2, 3]]