Python - eliminating common elements from two lists -


if have 2 lists:

a = [1,2,1,2,4] , b = [1,2,4] 

how

a - b = [1,2,4] 

such 1 element b removes 1 element if element present in a.

you can use itertools.zip_longest zip lists different length use list comprehension :

>>> itertools import zip_longest >>> [i i,j in izip_longest(a,b) if i!=j] [1, 2, 4] 

demo:

>>> list(izip_longest(a,b)) [(1, 1), (2, 2), (1, 4), (2, none), (4, none)] 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -