Skip to content

Instantly share code, notes, and snippets.

@kgaughan
Created April 25, 2012 17:54
Show Gist options
  • Select an option

  • Save kgaughan/2491663 to your computer and use it in GitHub Desktop.

Select an option

Save kgaughan/2491663 to your computer and use it in GitHub Desktop.

Revisions

  1. Keith Gaughan renamed this gist Apr 25, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Keith Gaughan created this gist Apr 25, 2012.
    15 changes: 15 additions & 0 deletions gistfile1.txt
    Original 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(',')])))