+ 2

how to Subtract 2 lists .

eg. a=[3,4,5,7,8,3] - b=[3,4,5,7] (need a simple way)

21st Aug 2018, 7:20 PM
Rishabh Mehta
4 ответов
+ 5
What do you mean by subtraction? Can you tell what is the expected output?
21st Aug 2018, 7:37 PM
Eduardo Petry
Eduardo Petry - avatar
+ 5
while b: x = b.pop() if x in a: a.remove(x) # now `a` is your desired output Edit: do you need a code snippet or is this sufficient?
21st Aug 2018, 7:42 PM
Eduardo Petry
Eduardo Petry - avatar
+ 4
a = [3,4,5,6] b = [3, 4] print([i for i in a if i not in b]) #5 6 import numpy as np a = np.array([3,4,5,6]) b = np.array([1,2,3,4]) print(a - b) #2 2 2 2
21st Aug 2018, 7:48 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 2
[8,3]
21st Aug 2018, 7:38 PM
Rishabh Mehta