Don't use re.findall()
. Your strings are always a number followed by a letter. So use a regular expression that matches just that pattern, rather than splitting it.
def string_split(type: str):
m = re.match('(d+)([A-Z])', type)
if m:
num = m.group(1)
unit = m.group(2)
if unit == 'D':
return num, 'days'
elif unit == 'M':
return num, 'months'
else:
raise ValueError('Invalid unit ' + unit)
else:
raise ValueError('Invalid interval ' + type)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…