Created
April 25, 2012 17:54
-
-
Save kgaughan/2491663 to your computer and use it in GitHub Desktop.
Revisions
-
Keith Gaughan renamed this gist
Apr 25, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Keith Gaughan created this gist
Apr 25, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ from itertools import chain def parse_range(rng): parts = rng.split('-') if 1 > len(parts) > 2: raise ValueError("Bad range: '%s'" % (rng,)) parts = [int(i) for i in parts] start = parts[0] end = start if len(parts) == 1 else parts[1] if start > end: end, start = start, end return range(start, end + 1) def parse_range_list(rngs): return sorted(set(chain(*[parse_range(rng) for rng in rngs.split(',')])))