Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String Split into separate Strings in python

Tags:

python

I want to split "Onehundredthousand" to "one" "hundred" "thousand" using python. How can I do that?

like image 817
Januka samaranyake Avatar asked Jan 31 '26 21:01

Januka samaranyake


2 Answers

You can use a string's partition method to split it into 3 parts (left part, separator, right part):

"onehundredthousand".partition("hundred")
# output: ('one', 'hundred', 'thousand')
like image 99
Byte Commander Avatar answered Feb 02 '26 11:02

Byte Commander


>>> s = "Onehundredthousand"
>>> s.replace('hundred', '_hundred_').split('_')
['One', 'hundred', 'thousand']

This will only work on the given string.

like image 38
AKS Avatar answered Feb 02 '26 10:02

AKS