我想要拆分"Onehundredthousand"到"one" "hundred" "thousand"使用python.我怎样才能做到这一点?
您可以使用字符串的partition方法将其拆分为3个部分(左侧部分,分隔符,右侧部分):
"onehundredthousand".partition("hundred")
# output: ('one', 'hundred', 'thousand')
Run Code Online (Sandbox Code Playgroud)
>>> s = "Onehundredthousand"
>>> s.replace('hundred', '_hundred_').split('_')
['One', 'hundred', 'thousand']
Run Code Online (Sandbox Code Playgroud)
这只适用于给定的字符串.