Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I split a word into 2 words in Python?

Example:
I am trying to split a list of column names called "startedat", "duecheck", "vehicleid" into "started" and "at", "due" and "check", "vehicle" and "id" respectively to get the desired output like started_at, due_check, vehicle_id.

I have tried using nltk word tokenize to split but it does not work. May I know what other methods I can do?

Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Install package

pip install wordninja

Code :

import wordninja

col_list = ["startedat", "duecheck", "vehicleid"]

result = ["_".join(wordninja.split(x)) for x in col_list]
print(result)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading