Write a program to replace multiple words with a single word
Topic: Write a program to replace multiple words with a single word
Solution
str1 = 'CoffeeDay is best for coffee and having long conversations' word_list = ["best", 'long'] repl_word = 'good' res = ' '.join([repl_word if idx in word_list else idx for idx in str1.split()]) print("String after multiple replace : " + str(res))
List all Python Programs