how to subtract 2 lists in python
[item for item in x if item not in y]
how to subtract 2 lists in python
[item for item in x if item not in y]
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)
python subtract lists
# Example usage using list comprehension:
list_a = [1, 2, 3]
list_b = [1, 1, 1]
[a_i - b_i for a_i, b_i in zip(list_a, list_b)]
--> [0, 1, 2]
subtract list from list python
>>> z = list(set(x) - set(y))
>>> z
[0, 8, 2, 4, 6]
python subtract list from list
[item for item in x if item not in y]
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us