split python list code example
Example 1: python split by list
def split(txt, seps):
default_sep = seps[0]
for sep in seps[1:]:
txt = txt.replace(sep, default_sep)
return [i.strip() for i in txt.split(default_sep)]
>>> split('ABC ; DEF123,GHI_JKL ; MN OP', (',', ';'))
['ABC', 'DEF123', 'GHI_JKL', 'MN OP']
Example 2: split string python
file='/home/folder/subfolder/my_file.txt'
file_name=file.split('/')[-1].split('.')[0]
Example 3: python split list
string = 'this is a python string'
wordList = string.split(' ')
Example 4: python split list
string = "this is a string"
splited_string = string.split(" ")
print(splited_string)