
July 23, 2009
9:12 a.m.
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.