How to add "_" after splitting word in Python?
Question:
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?
arr_list = ['startedat', 'duecheck', 'vehicleid']
for word in arr_list:
print(word_tokenize(word))
Thank you.
Answers:
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)
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?
arr_list = ['startedat', 'duecheck', 'vehicleid']
for word in arr_list:
print(word_tokenize(word))
Thank you.
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)