0

So for example I have two lists like this and I want to compare the lists inside the two list

a = [[1,2],[3,4],[4,5]]

b = [[1,2],[4,5],[5,6]]

if [1,2] = [1,2] then it should append to another list(also for [4,5]) The point is I can't think of how to get the [4,5] into the new list

and [3,4] and [5,6] should not be appended

Here is the actual problem I am solving

Frame

So each list has 4 elements and it will have another column for classification I have 2 datasets and I want to compare the coordinates in order to map the Name of the first table to the Name of the second table

  • There is a similar question and many answers. It's about 1d array, but you're comparing the whole second dimension, which is 1d problem - https://stackoverflow.com/questions/31206106/compare-each-item-of-two-lists-in-python – Morticia A. Addams Apr 12 '22 at 18:37

1 Answers1

0

You can do so with list comprehension

a = [[1,2],[3,4],[4,5]] 
b = [[1,2],[4,5],[5,6]]

print([e for e in a if e in b])

>>> [[1, 2], [4, 5]]
ScootCork
  • 3,411
  • 12
  • 22