Skip to content

Instantly share code, notes, and snippets.

@dbadrian
Created March 6, 2019 14:32
Show Gist options
  • Save dbadrian/1dab7e388dde2d1bffb5f3e372b02fec to your computer and use it in GitHub Desktop.
Save dbadrian/1dab7e388dde2d1bffb5f3e372b02fec to your computer and use it in GitHub Desktop.
parse range
def parse_range(astr):
""" Takes a string like "1-3,5,7-9" and returns a list [1,2,3,5,7,8,9] """
result = set()
for part in astr.split(','):
x = part.split('-')
result.update(range(int(x[0]), int(x[-1]) + 1))
return sorted(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment