I didn’t know how to properly define this question, but here’s the problem.
I have two lists like this:
x = ['Monday', 'Tuesday', 'Wednesday', 'Thursday']
z = ['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
I’d like to match up the two lists and remove any items that do not exist in both lists. That means that the output would in this case be:
y = ['Wednesday', 'Thursday']
I tried using the zip() function but couldn’t get it to work. Do you have any ideas?
Thanks beforehand.
>Solution :
Do this:
x = ['Monday', 'Tuesday', 'Wednesday', 'Thursday']
z = ['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
res = list(set(x)&set(z))
print(res)
This would give you the desired result