-3

I have two lists, A1 and A2 with indices. I want to find out A1 - A2. The desired output is attached.

A1= [(0,0),(0,1),(0,2),(1,0),(1,1),(2,1),(2,0),(2,1),(2,2)]
A2= [(0,0),(0,1),(0,2)]

The desired output is

[(1,0),(1,1),(2,1),(2,0),(2,1),(2,2)] 
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Wiz123
  • 904
  • 8
  • 13

2 Answers2

0

You may try something like this

A3 = [i for i in A1 if not i in A2]
print(A3)
Python learner
  • 1,159
  • 1
  • 8
  • 20
0

Just use list.remove

You can iterate in the list A2 and remove each element from A1:

A1= [(0,0),(0,1),(0,2),(1,0),(1,1),(2,1),(2,0),(2,1),(2,2)]
A2= [(0,0),(0,1),(0,2)]

for idx in A2:
   A1.remove(idx)
print(A1)

and the output should be:

[(1, 0), (1, 1), (2, 1), (2, 0), (2, 1), (2, 2)]