CoCalc Shared Fileswww / cgi-bin / mfd / mfe_misc.pyOpen in CoCalc with one click!
Author: William A. Stein
1
def isnumerical(a):
2
return '0' <= a <= '9'
3
4
def parse_level_weight(s):
5
t=""
6
for i in range(len(s)):
7
if isnumerical(s[i]):
8
t=t+s[i]
9
elif s[i] == "-":
10
return [0, "", 0]
11
else:
12
t=t+" "
13
x = t.split()
14
level = "1"
15
weight = "2"
16
if len(x) == 1:
17
level = x[0]
18
elif len(x) >= 2:
19
level = x[0]
20
weight = x[1]
21
if len(level) > 9 or len(weight) > 9:
22
return [0, "", 0]
23
return [1, level, weight]
24
25
26