d = 'rlg3-22'
import re
ops = re.findall(r"\d+",d) # r"\d+" searches for digits of variables length
prefix = re.findall(r"\D+", d)[0] # r"\D+" complement set of "\d+"
构建列表并将前缀添加到整数的字符串强制转换中
[prefix + str(i) for i in list(range(int(ops[0]), int(ops[1]),1))]
['rgl3',
'rgl4',
'rgl5',
'rgl6',
'rgl7',
'rgl8',
'rgl9',
'rgl10',
'rgl11',
'rgl12',
'rgl13',
'rgl14',
'rgl15',
'rgl16',
'rgl17',
'rgl18',
'rgl19',
'rgl20',
'rgl21']
构建列表并将前缀添加到整数的字符串强制转换中
相关问题 更多 >
编程相关推荐