codehaus


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Any better way for this removal?



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)