Python 如何拆分包含数字和字符的字符串

Python 如何拆分包含数字和字符的字符串,python,string,split,Python,String,Split,我想在Python中将一个长字符串(其中包含数字和字符,没有任何空格)拆分为不同的子字符串 >>> s = "abc123cde4567" 拆分后将获得 ['abc', '123', 'cde', '4567'] 谢谢大家! 与正则表达式不同的东西: >>> import re >>> re.findall("[a-z]+|[0-9]+", "abc123cde4567") ['abc', '123', 'cde', '4567'] f

我想在Python中将一个长字符串(其中包含数字和字符,没有任何空格)拆分为不同的子字符串

>>> s = "abc123cde4567"
拆分后将获得

['abc', '123', 'cde', '4567']

谢谢大家!

与正则表达式不同的东西:

>>> import re
>>> re.findall("[a-z]+|[0-9]+", "abc123cde4567")
['abc', '123', 'cde', '4567']
from itertools import groupby
from string import digits

s = "abc123cde4567"
print [''.join(g) for k, g in groupby(s, digits.__contains__)]
# ['abc', '123', 'cde', '4567']

与正则表达式不同的东西:

from itertools import groupby
from string import digits

s = "abc123cde4567"
print [''.join(g) for k, g in groupby(s, digits.__contains__)]
# ['abc', '123', 'cde', '4567']

欢迎来到SO!请包括您解决问题的尝试,以便我们可以显示您出错了。否则,您可能会被否决和/或问题结束。欢迎使用SO!请包括您解决问题的尝试,以便我们可以显示您出错了。否则,您可能会被否决和/或问题结束。