Skip to content

Instantly share code, notes, and snippets.

View icb_industries.json
"icb": "0001",
"supersectors": [
"icb": "0500",
"name": "Oil & Gas",
"sectors": [
"icb": "0530",
barszczmm /
Last active Jan 3, 2016
Functions for combining/merging lists or tuples representing ranges and for subtracting ranges of one list of ranges from ranges of second list of ranges.
#!/usr/bin/env python
def combine_ranges(ranges, are_touching=lambda x, y: y - x == 1):
Create new list of ranges combining ranges if they overlap
or touch each other.
Examples using integers:
>>> combine_ranges(((1,5), (3,7)))