
2008/6/3 Arnaud Delobelle <arnodel@googlemail.com>:
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
I've written a patch [1] that does that. Following the suggestion of Raymond Hettinger, I've implemented set.intersection by sorting all its sets/frozensets/dicts in increasing order of size first, then iterating over the smallest. It's the first time I try my hand at this so it might not be up to much, but I've made it so I might as well send it :). It's against py3k svn. [1] http://bugs.python.org/issue3069 -- Arnaud