[Python-ideas] Implement __add__ for set and frozenset
Arnaud Delobelle
arnodel at googlemail.com
Tue Jun 3 19:28:03 CEST 2008
On 3 Jun 2008, at 02:21, George Sakkis 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
>
Perhaps it would be nice to have set.union (and set.intersection) to
accept more than one argument, i.e. have
A = S.union(T, U, V)
mean
A = S.union(T)
A.update(U)
A.update(V)
As a consequence of Python method implementation, one could write
instead:
A = set.union(S, T, U, V)
B = set.intersection(S, T, U, V)
which reads nicely
--
Arnaud
More information about the Python-ideas
mailing list