[Python-ideas] universal set object for use in set manipulation

Jan Kaliszewski zuo at chopin.edu.pl
Fri Jul 24 02:48:38 CEST 2009


Mike Meyer <mwm-keyword-python.b4bdba at mired.org>:

> On the other hand, adding negative sets to the language provides an
> easy way to express that constant, and certainly have more uses in
> general. If we had to add one of the two, it'd be these. But I'm not
> convinced that these have enough uses to justify adding them, either.

Yeah, I feel, that if a group of people need them, they should have
a separate type ("negative" or "infitity-minus..." or "universe
without..."-) sets, in a separate module (not necessarily in std
library).

It would be a type which can interact in some ways with sets (like
e.g. dict views do...).

As it was noted -- some sets' features don't make sense here...
(len, iter).

But many do:

a in universe_minus()
-> True

a in universe_minus([a, b, c])
-> False

set([a, b]) < universe_minus()
-> True

set([a, b]) < universe_minus([b, c])
-> False

universe_minus().remove(a)
-> universe_minus([a])

universe_minus([a, b, c]).remove(a)
-> KeyError

universe_minus([a]).add(a)
-> universe_minus([])

universe_minus().add(a)
-> universe_minus([])

universe_minus() - set([a, b, c])
-> universe_minus([a, b, c])

universe_minus() & set([a, b, c])
-> set([a, b, c])

universe_minus() | set([a, b, c])
-> universe_minus()

universe_minus() - universe_minus([a, b])
-> set([a, b])

universe_minus() & universe_minus([a, b])
-> universe_minus([a, b])

universe_minus() | universe_minus([a, b])
-> universe_minus()

universe_minus([a, b, c]) - set([a, b])
-> universe_minus([a, b, c])

universe_minus([a, b, c]) | set([a, b])
-> universe_minus([c])

universe_minus([a, b]) ^ set([a, b, c])
-> universe_minus([c])

etc.



More information about the Python-ideas mailing list