[Python-ideas] universal set object for use in set manipulation

Georg Brandl g.brandl at gmx.net
Thu Jul 23 09:04:22 CEST 2009


Andy Kish schrieb:

> Instead you have to do something contorted like:
> 
>     if len(sets) == 0:
>         set_intersection = set()
>     else:
>         sets_i = iter(sets)
>         set_intersection = sets_i.next()
>         for s in sets:
>             set_intersection &= s

Note that a simple ``reduce(operator.and_, sets)`` would suffice for > 1 set.

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.




More information about the Python-ideas mailing list