[Python-ideas] universal set object for use in set manipulation
Andrew Bennetts
andrew at bemusement.org
Thu Jul 23 09:12:07 CEST 2009
Andy Kish wrote:
[...]
>
> The above intersection case would end up looking something like:
>
> set_intersection = set.universal()
> for s in sets:
> set_intersection &= s
Or even:
set_intersection = reduce(operator.and_, sets, set.universal())
Although, you can already pass multiple (or zero) sets to set.intersection().
So your special case version can be a little simpler...
sets = list(sets)
if len(sets) == 0:
return set()
return sets[0].intersection(sets[1:])
Which isn't as elegant, but it's also not so bad.
-Andrew.
More information about the Python-ideas
mailing list