> For cases where the number of elements in the range is not ridiculously > large, simply converting to sets is probably sufficient: >
Sets don’t preserve order, which may or may not be important— but as the IP didn’t provide a use case, I have no idea. To the OP: this idea isn’t likely y on be accepted into Python itself without some compelling use cases. But it’s nifty idea -. A great candidate for a prototype library that you can use to work out the details and demonstrate its utility. Once you’ve done that, it may (or may not) make sense to propose an extension to tbe builtin range object. -CHB > >>> set(range(10)) - set(range(5)) == set(range(5, 10)) > True > >>> set(range(3,5,2)) | set(range(3,6,2)) == set(range(3,6,2)) > True > > For sufficiently large ranges, there are bitset classes on PyPI that might > be more memory efficient. Or if you're looking for some other types of > operation (unbounded ranges, or specialised abstract algebra operations) a > custom class (maybe even published on PyPI) would probably be a better > approach than trying to get something that specialised added to the stdlib. > > Paul > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/EMDUKIHECPQJETKGYNPJPXT7VV6Y2HCH/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/WXPBMTP7RGB3LM2DM4K3JPBELGFSQVTL/ Code of Conduct: http://python.org/psf/codeofconduct/