add mark into sentence if some word in sentence
Question:
I have a table like below
sentence
key phase
I love Python
love Python
I love Coding
love Coding
I want to add the mark $ and /$ in the head and tail of the key phase like below.
sentence
key phase
I $love Python/$
love Python
I $love Coding/$
love Coding
Any one know how to do this?
Answers:
What have you tried so far? It’s helpful for others to help you debug.
This may be a starting point to help though
def transform_string(input_string, key_phrase):
return input_string.replace(key_phrase, f"${key_phrase}/$")
input_string = "I love Python"
key_phrase = "love Python"
transformed_string = transform_string(input_string, key_phrase)
print(transformed_string)
I have a table like below
sentence | key phase |
---|---|
I love Python | love Python |
I love Coding | love Coding |
I want to add the mark $ and /$ in the head and tail of the key phase like below.
sentence | key phase |
---|---|
I $love Python/$ | love Python |
I $love Coding/$ | love Coding |
Any one know how to do this?
What have you tried so far? It’s helpful for others to help you debug.
This may be a starting point to help though
def transform_string(input_string, key_phrase):
return input_string.replace(key_phrase, f"${key_phrase}/$")
input_string = "I love Python"
key_phrase = "love Python"
transformed_string = transform_string(input_string, key_phrase)
print(transformed_string)