On Thu, Feb 21, 2013 at 5:50 AM, Yuval Greenfield <ubershmekel@gmail.com> wrote:
On Thu, Feb 21, 2013 at 3:35 PM, Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> wrote:
a = range(1,10)
b = range(5,12)
intersect = a & b     # equivalent to intersect = range(5,10)
merge = a | b         # equivalent to merge = range(1,12)

... 
this whole idea is reminiscent, of course, of what's implemented for sets
already, so like there you could think of
intersect = a & b as shorthand for intersect = a.intersection(b)

I think each operation you implement can have a lot of different bikeshed details. Since these are all very simple to begin with, it's better to not burden the language and just let users implement whatever it is they need.


Ignoring performance issues, imagine instead a sorted set class that you could add ranges to (or remove them). Well, actually it's trivial to convert a range to a set; the interesting problem is performance. You could save the range parts unexpanded so you could add huge ranges and you could also support infinite ranges (itertools.count).

I suggest this because once you consider doing the first set of operations, like r1 & r2, it's quite natural for someone to want 

some_non_unlucky_integers = range(100) - [13]

The idea of a sorted set class is, of course, not original. See for example http://stutzbachenterprises.com/blist/sortedset.html. If SortedSet isn't in the stdlib, I can't imagine this enhancement being either.

--- Bruce
Latest blog post: Alice's Puzzle Page http://www.vroospeak.com