0

Is there a more pythonic / efficient way of finding and replacing text between two words in a string?

string = "<start>processing<end>"

# Create start and stop indexes to get text between two words
start = string.find("<start>") + len("<start>")
end = string.find("<end>")
substrig = string[start:end]

# Update the word
string = string.replace(substrig, "Shipped")

print(string)
# Prints <start>Shipped<end>
juju
  • 884
  • 1
  • 9
  • 31

0 Answers0