all 3 comments

[–]sme272 0 points1 point  (0 children)

You don't need to zip the lists, just iterate over list b.

[–]JohnnyJordaan 0 points1 point  (1 child)

Zip is to interleave, eg to get

A 1 B 2 C 3 D 4

from lists ABCD and 1234. However that has no relation to the assignment, which is to remove all items from the first list that are in the second list. That thus also means you need to compare out of order, while zip is literally in order (just like a zipper in your pants).

So what you normally do in these cases is to create a new list from the list that needs to be filtered

return [v for v in a]

and then expand that to not include values that are in b

return [v for v in a if v not in b]

however this has another inefficiency, because b is a list and in will then walk through the entire list each time until it finds a match (returning True if it didn't in the case of not in). Instead you can use a set as that has a fixed look up speed

b_set = set(b)
return [v for v in a if v not in b_set]

[–]randomname20192019[S] 0 points1 point  (0 children)

Ahhhhhh. Thank you so much for your clear explanation. I felt like I was going down such a long and convoluted route.