On Thu, Feb 21, 2013 at 3:35 PM, Wolfgang Maier wrote:
Dear all,
what do you think about allowing the use of operators on ranges?

I thought of things like:
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)

to make this work in more complex cases, like:
a = range(1,10)
b = range(12,15)
merge = a | b         # equivalent to sth. like range(range(1,10),range(12,15))

maybe range nesting would be desirable, but the full sequence of values of such
a nested range could still be calculated on demand.

Such syntax would allow for the generation of more complex sequences, and, as a
side-effect, ranges could also be checked for overlap easily:
if a & b:
do_something()

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)

Opinions?

This has been suggested in the past.

http://mail.python.org/pipermail/python-bugs-list/2012-June/173343.html

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.

Though, maybe you can show some popular and compelling use cases in the wild?

Yuval Greenfield