[Python-ideas] Implement __add__ for set and frozenset

George Sakkis george.sakkis at gmail.com
Tue Jun 3 03:21:32 CEST 2008

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:

I wouldn't mind having a standard unionall, but not every 3-line function
has to be in the stdlib.


On Mon, Jun 2, 2008 at 7:48 AM, Brandon Mintern <bmintern at gmail.com> wrote:

> I would like to propose that the + operator be a synonym for | (union)
> on sets. IMHO, the succinct power of being able to say
> sum(list_of_sets, set())
> as opposed to
> import operator
> reduce(operator.and_, list_of_sets, set())
> far outweighs any problems with having two operators for union. The
> sum paradigm is certainly more readable as well. I realize that a
> function named "unionall" could be defined trivially, but with a
> built-in already serving the purpose in a readable and reasonable way,
> it seems silly to not use it.
> I anticipate that someone will ask why such a paradigm should be
> available for union as opposed to the other set operations. My answer
> is that several standard algorithms rely on a union over a sequence of
> sets; one example is the construction of the "follow" set in
> constructing an LL or SLR parser, and I know I've seen others that I
> cannot remember off the top of my head. There is even a mathematical
> symbol (big-U) for it akin to the summation sign (uppercase sigma).
> Any feedback?
> Brandon
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20080602/00611771/attachment.html>

More information about the Python-ideas mailing list