How to split a string without removing the delimiter in Python

1 Answer

0 votes
string = 'python_java_c_c++_c#'

delimiter = '_'

lst= [w + delimiter for w in string.split(delimiter) if w]

print(lst)

 


'''
run:

['python_', 'java_', 'c_', 'c++_', 'c#_']

'''
 
 

 



answered Aug 6, 2022 by avibootz
...