From f60e0bec3f5b5d967fb80cb4e29d9cc67806be17 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Sat, 29 Aug 2015 22:22:45 -0700 Subject: [PATCH] copy d341813e62df969980c719133bd826ca8654ae04 --- pirate/pirate.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pirate/pirate.py b/pirate/pirate.py index eb341f3..d5c0505 100755 --- a/pirate/pirate.py +++ b/pirate/pirate.py @@ -235,8 +235,20 @@ def main(): # Turn into list l = re.sub(r'^[hdfp, ]*|[hdfp, ]*$', '', l) l = re.sub('[ ,]+', ',', l) - l = re.sub('[^0-9,]', '', l) - choices = l.split(',') + l = re.sub('[^0-9,-]', '', l) + parsed_input = l.split(',') + + # expand ranges + choices = [] + for elem in parsed_input: # loop will generate a list of lists + left, sep, right = elem.partition('-') + if right: + choices.append(list(range(int(left), int(right) + 1))) + else: + choices.append([int(left)]) + choices = sum(choices, []) # flatten list + choices = [str(elem) for elem in choices] # the current code stores the choices as strings instead of ints. not sure if necessary + # Act on option, if supplied print('')