-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecodeRange.py
More file actions
executable file
·60 lines (47 loc) · 1.53 KB
/
Copy pathdecodeRange.py
File metadata and controls
executable file
·60 lines (47 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import re
def decodeRange():
range = input("Enter range of episodes: ")
if re.match("\ *",range) or range == "":
return None
inputs = range.split(" ")
revisedInputs = []
for x in inputs:
if re.match("\d+\d+\-\d+\d*|(\d+\,)+\d*|(\d+)+",x) != None and not re.search("[a-zA-z]",x):
revisedInputs.append(x)
groupNumbers = []
ranges = []
individualNumbers = []
for x in revisedInputs:
if re.search("-",x) and not re.search("a-zA-Z",x):
ranges.append(x)
elif re.match("\d+\d*\-\d+\d*|(\d+\,)+\d*",x) and not re.search("a-zA-Z",x):
groupNumbers.append(x)
elif re.match("(\d+)+",x):
individualNumbers.append(x)
splittedRanges = []
for x in ranges:
splittedRanges.append(tuple(x.split("-")))
numbersSet = set()
for x in splittedRanges:
if int(x[0]) > int(x[1]):
splittedRanges.remove(x)
for x in splittedRanges:
index = int(x[0])
while index <= int(x[1]):
numbersSet.add(index)
index = index +1
splittedNumbersLists = []
for x in groupNumbers:
splittedNumbersLists.append(x.split(","))
for x in splittedNumbersLists:
for y in x:
if y == "":
x.remove(y)
for x in splittedNumbersLists:
for y in x:
numbersSet.add(int(y))
for x in individualNumbers:
numbersSet.add(int(x))
numbersList = list(numbersSet)
numbersList.sort()
return numbersList