mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
Merge pull request #55 from jebaum/allow-ranges
allow ranges of values to be entered
This commit is contained in:
commit
5f11463a0f
@ -623,8 +623,19 @@ def main():
|
|||||||
# Turn into list
|
# Turn into list
|
||||||
l = re.sub(r'^[hdfp, ]*|[hdfp, ]*$', '', l)
|
l = re.sub(r'^[hdfp, ]*|[hdfp, ]*$', '', l)
|
||||||
l = re.sub('[ ,]+', ',', l)
|
l = re.sub('[ ,]+', ',', l)
|
||||||
l = re.sub('[^0-9,]', '', l)
|
l = re.sub('[^0-9,-]', '', l)
|
||||||
choices = l.split(',')
|
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
|
# Act on option, if supplied
|
||||||
print('')
|
print('')
|
||||||
|
Loading…
Reference in New Issue
Block a user