I am trying to merge sets defined in a set and this is what I have now
a = frozenset([1,3,4])
b = frozenset([1,2,3,4,5])
s = set()
s.add(a)
s.add(b)
merged = set(itertools.chain.from_iterable(s))
In practice, s
may contain many frozensets. Is there better ways to do it? It feels like a reduce
case, but
from functools import reduce
merged = reduce(|, s)
doesn't work.
Also
merged = reduce(set.add, s)
doesn't work because the elements of s
are frozensets.
|
as a standalone function is known asoperator.or_
– Seymour