I've created a list of sets that I'd like to pass into set.intersection()
For example:
List_of_Sets = [{1,2,3},{3,4,5},{5,6,7}]
set.intersection(List_of_Sets)
Result:
TypeError: descriptor 'intersection' requires a 'set' object but received a 'list'
Desired Output:
{3,5}
How would I pass each set within the list as a separate argument into set.intersection()?
Use the unpacking operator: set.intersection(*List_of_Sets)
As pointed out in the other answer, you have no intersections in the list. Do you want to compute the union of the intersection of adjacent elements?
>>> set.union(*[x & y for x, y in zip(List_of_Sets, List_of_Sets[1:])])
set([3, 5])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With