我无法解析包含字母和数字的字符串并返回列表。例如:
>>> s = '105Bii2016'
>>> foo(s)
['105', 'Bii', '2016']
现在我只能在数字在一起的情况下做到这一点:
def foo(s):
num, letter = '', ''
for i in s:
if i.isdigit():
num += i
else:
letter += i
return [letter, num]
当我称之为:
>>> s = '1234gdfh1234'
>>> foo(s)
['gdfh', '12341234']