
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 On Mon, Jun 2, 2008 at 7:48 AM, Brandon Mintern <bmintern@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@python.org http://mail.python.org/mailman/listinfo/python-ideas