Suppose I have a list of sets and I want to get the union over all sets in that list. Is there any way to do this using a generator expression? In other words, how can I create the union over all sets in that list directly as a frozenset?
frozenset
Just use the .union() method.
.union()
>>> l = [set([1,2,3]), set([4,5,6]), set([1,4,9])] >>> frozenset().union(*l) frozenset([1, 2, 3, 4, 5, 6, 9])
This works for any iterable of iterables.
1.4m articles
1.4m replys
5 comments
57.0k users