-3

I'm stuck with a part in one of my codes where I have to delete all the occurances present in listA that are identical in listB.

Example:

A=[1,4,4,4,3,3,2,1,5,5]
B=[4,3] 

Result should be A=[1,2,1,5,5]. Ideally I would want to do it in linear time.

Rahul K P
  • 10,793
  • 3
  • 32
  • 47
Sai Pardhu
  • 287
  • 1
  • 11

2 Answers2

1

using Set Operations:

list(set(A) - set(B))

Using List Comprehension

list(set([i for i in A if i not in B]))
Mithilesh Gupta
  • 2,652
  • 1
  • 15
  • 17
0

Try with list comprehension,

In [11]: [i for i in A if i not in B]
Out[11]: [1, 2, 1, 5, 5]
Rahul K P
  • 10,793
  • 3
  • 32
  • 47