Skip to main content

A Range is an object resembling a set but optimised for contiguous ranges of int members.

Latest release 20230518: Span,Range: new as_list() methods.

Function overlap(span1, span2)

Return a list [start,end] denoting the overlap of two spans.

Example:

>>> overlap([1,9], [5,13])
[5, 9]

Class Range

A collection of ints that collates adjacent ints.

The interface is as for a set with additional methods:

  • spans(): return an iterable of Spans, with .start included in each Span and .end just beyond

Additionally, the update/remove/etc methods have a secondary calling signature: (start,end), which is the same as passing in Range(start,end) but much more efficient.

Method Range.__init__(self, start=None, end=None, debug=None): Initialise the Range.

Called with start and end, these specify the initial Span of the Range. If called with just one argument that argument instead be an iterable of integer values comprising the values in the Range.

Class Span(Span, builtins.tuple)

A namedtuple with .start and .end attributes.

Function spans(items)

Return an iterable of Spans for all contiguous sequences in items.

Example:

>>> list(spans([1,2,3,7,8,11,5]))
[1:4, 7:9, 11:12, 5:6]

Release Log

Release 20230518: Span,Range: new as_list() methods.

Release 20190102: Span: provide len.

Release 20171231:

  • Add Range.span0, returning the first Span.
  • Implement bool and__nonzero__.
  • Accept a Span in contains.
  • Some small bugfixes.

Release 20160828:

  • Add Range.start like existing Range.end.
  • Use "install_requires" instead of "requires" in DISTINFO.
  • Small bugfix.

Release 20150116: First PyPI release.

Release files for cs.range 20230518

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs.range 20230518
File Size Uploaded
cs.range-20230518.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cs.range 20230518
File Interpreter ABI Platform
cs.range-20230518-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / cs.range-20230518.tar.gz

Download URL cs.range-20230518.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fa50f8aa968c231ea9b7fbb2f6dc148ac5cf1cafad4ad3ff71b18c08280f1f6c
BLAKE2b-256 checksum
How to use checksums
42a4de45756c68f0bb296f04be0bc3640dbe503fc3dafdf6ae8108bc6ae66fd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / cs.range-20230518-py3-none-any.whl

Download URL cs.range-20230518-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd84b12c1d1965be317ba662c95f9be6369bc43bfafba1bcab2babeab62e546a
BLAKE2b-256 checksum
How to use checksums
5105114c0e37cc73d89d68e410ac972e0991739ac7aa9c81fd78f3bd59cdd267
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

20230518 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page