-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
  • 15,740
  • 4
  • 35
  • 52
Sai Pardhu
  • 289
  • 1
  • 12

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,800
  • 1
  • 17
  • 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
  • 15,740
  • 4
  • 35
  • 52