[Python-ideas] Implement __add__ for set and frozenset

Brandon Mintern bmintern at gmail.com
Tue Jun 3 03:28:44 CEST 2008

On Mon, Jun 2, 2008 at 9:21 PM, George Sakkis <george.sakkis at gmail.com> wrote:
> Regardless of the operator, that's a pretty inefficient way of doing
> "unionall"; it creates N-1 intermediate result sets that discards them right
> after they are added. It should be written as:
> big_u = set()
> for s in all_sets:
>     big_u.update(s)
> I wouldn't mind having a standard unionall, but not every 3-line function
> has to be in the stdlib.
> George

I thought max was implemented using += (i.e. it usually starts at 0
and uses += on each item in the iterable). If so, implementing **
_iadd_ ** would result in exactly the code you posted. I realize that
I said __add__ in the first place, but __iadd__ is really what I


More information about the Python-ideas mailing list