To subtract a list of strings from another, you can use list comprehension along with not in
operator. Here's an example:
main.py184 chars7 lines
In the code above, we first declare list1
and list2
containing the lists of strings that we want to subtract. We then use list comprehension to create a filtered list that contains only the elements from list1
that are not in list2
. The result is stored in result_list
.
The output indicated on the comment should be ['apple', 'orange']
which is list1
without list2
elements.
I hope this helps!
gistlibby LogSnag