Is there a way to get the difference and intersection of tuples or lists in Python? [duplicate]
问题 This question already has answers here : Find intersection of two nested lists? (19 answers) Closed 5 years ago . If I have lists: a = [1, 2, 3, 4, 5] b = [4, 5, 6, 7, 8] c = a * b should give me: c = [4, 5] and c = a - b should give me: c = [1, 2, 3] Is this available for Python or do I have to write it myself? Would the same work for tuples? I will likely use lists as I will be adding them, but just wondering. 回答1: If the order doesn't matter, you can use set for this. It has intersection