Answers for "how to subtract a list from other list in python?"

2

python subtract one list from another

# Subtract list1 from list2 (find only items not in both lists)
list1 = [2, 2, 2]
list2 = [1, 1, 1]
difference = []   # initialization of result list

zip_object = zip(list1, list2)

for list1_i, list2_i in zip_object:
    difference.append(list1_i-list2_i) # append each difference to list

print(difference)
Posted by: Guest on November-30-2020
1

subtract list from list python

>>> z = list(set(x) - set(y))
>>> z
[0, 8, 2, 4, 6]
Posted by: Guest on November-08-2020

Code answers related to "how to subtract a list from other list in python?"

Python Answers by Framework

Browse Popular Code Answers by Language