I want to split "Onehundredthousand" to "one" "hundred" "thousand" using python.
How can I do that?
-
1post ur attempts..Avinash Raj– Avinash Raj2016-04-22 06:28:57 +00:00Commented Apr 22, 2016 at 6:28
-
2Just for this particular string,there can n different solutions. But if you want a generic solution,u need to have some delimiters.Mayur Buragohain– Mayur Buragohain2016-04-22 07:05:21 +00:00Commented Apr 22, 2016 at 7:05
Add a comment
|
3 Answers
>>> s = "Onehundredthousand"
>>> s.replace('hundred', '_hundred_').split('_')
['One', 'hundred', 'thousand']
This will only work on the given string.
1 Comment
Andrés Pérez-Albela H.
Using replace and then split? It's better to use partition.
Using regular expression re.split. If you use captured group as a separator, it will be also included in the result list:
>>> import re
>>> re.split('(hundred)', 'Onehundredthousand')
['One', 'hundred', 'thousand']
1 Comment
Januka samaranyake
Thanks for your support