List comprehension and intersection problem [duplicate]
问题 This question already has answers here : Best way to find the intersection of multiple sets? (5 answers) Closed 12 days ago . list(set(a[0]) & set(a[1]) & set(a[2]) & set(a[3]) & set(a[4])) Does anyone know how to write this in a way such that we dont need to know apriori how many lists we will be given? (ie 5 not hard coded in)? Each a is a list of varying size. 回答1: As long as you have at least one set, you can do this: list(set(a[0]).intersection(*a[1:])) If there might be no sets, you