In this program, we will take a string as input and replace multiple words with certain words.
Steps to solve the program
- Take a string as input.
- Convert the string of words into a list of words using split().
- Use for loop with range() function to iterate over each word in the list.
- Replace the word in the string with a defined word.
- Convert the list into a string using join().
- Print the output.
#Input string
string = "I’m learning python at Sqatools"
List = string.split(" ")
for i in range(len(List)):
if List[i] == "python":
List[i] = "SQA"
elif List[i] == "Sqatools":
List[i] = "TOOLS"
#Printing output
print(" ".join(List))
Output :
I’m learning SQA at TOOLS