Any better way for this removal?

Bischoop Bischoop at vimart.net
Sat Nov 7 08:46:17 EST 2020



So I was training with slicing. 
Came to idea to remove text after second occurence of character, below
is how I've figured it out, I know if it works it good but.... how you
guys would made it in more pythonic way?

text = "This is string, remove text after second comma, to be removed."

k=  (text.find(",")) #find "," in a string
m = (text.find(",", k+1)) #Find second "," in a string
new_string = text[:m]

print(new_string)




More information about the Python-list mailing list