+ 2

How to replace multiple words in a phrase in python using replace() function?

28th Jun 2021, 9:58 AM
Madhav Nandhi Vardhan Appana
Madhav Nandhi Vardhan Appana - avatar
24 Réponses
+ 2
Shadoff And one thing you are not a determiner to say to delete my question
28th Jun 2021, 11:35 AM
Madhav Nandhi Vardhan Appana
Madhav Nandhi Vardhan Appana - avatar
+ 4
You can do this using for loop: https://code.sololearn.com/ca734a4A6A14 There are also other ways of doing this. Here is the resource: https://stackoverflow.com/questions/6116978/how-to-replace-multiple-substrings-of-a-string
29th Jun 2021, 11:51 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
use replace function multiple times
28th Jun 2021, 9:59 AM
Shadoff
Shadoff - avatar
+ 1
Is there any other short way
28th Jun 2021, 10:02 AM
Madhav Nandhi Vardhan Appana
Madhav Nandhi Vardhan Appana - avatar
+ 1
Also I hope you know about lower(), isalpha(), isdigit() functions? which are useful when working with the strings
28th Jun 2021, 10:21 AM
Shadoff
Shadoff - avatar
+ 1
Buddy, you need to finish python core course then
28th Jun 2021, 10:23 AM
Shadoff
Shadoff - avatar
+ 1
Python core, python intermediate
28th Jun 2021, 10:27 AM
Shadoff
Shadoff - avatar
+ 1
没事, 都是可以。但是,最好 如果 你开始 python core, 然后python intermediate
28th Jun 2021, 10:34 AM
Shadoff
Shadoff - avatar
+ 1
YOU HAVE A LOT ROADS TO WALK OUT. it was just a test. And you didn't pass it. Let me give you a free advice. Google, and Google translate is your friends! This thread is not program related anymore. Please delete your Question
28th Jun 2021, 10:39 AM
Shadoff
Shadoff - avatar
+ 1
Madhav Nandhi Vardhan Appana I would suggest you learn Python Intermediate, then Python Core. You will find a lot of the lessons in Core are repeats of the previous lessons, but it will make for good revision. Do you have a concept / code to show of what you are trying to achieve with your original post. There may be a number of ways to achieve the result if a clear example is given
28th Jun 2021, 11:21 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Madhav Nandhi Vardhan Appana Awesome! Take your time and restructure your attempt. When you are ready, post your attempt here & we will be able to see where your problem is (hopefully) Then we should be able to guide you to a resolution. I seem to remember there was a trick involving 10 in the challenge, you may need to read the challenge carefully. Let us know how you get on.
28th Jun 2021, 11:36 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Here's a possibility: repl = {"C": "low", "python": "high2", "Java": "high1"} sent = input() for x in repl: sent = sent.replace(x, repl[x]) # More words may be added # Hope this helps
28th Jun 2021, 4:20 PM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Calvin Thomas Thank you for your answer
28th Jun 2021, 4:33 PM
Madhav Nandhi Vardhan Appana
Madhav Nandhi Vardhan Appana - avatar
+ 1
The only solution to this is by using a loop
29th Jun 2021, 3:08 PM
Mayank Gupta
Mayank Gupta - avatar
0
yes. you can use predefined dictionary in the user defined function. which will take as an argument string, and returns new string where: all words in the dictionary keys will be replaced with the dictionary's value. got it?
28th Jun 2021, 10:16 AM
Shadoff
Shadoff - avatar
0
I will try it Thank you for your answer.
28th Jun 2021, 10:17 AM
Madhav Nandhi Vardhan Appana
Madhav Nandhi Vardhan Appana - avatar
0
No I don't know But I will learn them
28th Jun 2021, 10:22 AM
Madhav Nandhi Vardhan Appana
Madhav Nandhi Vardhan Appana - avatar
0
I had completed python for beginners course , What should I have to complete now
28th Jun 2021, 10:25 AM
Madhav Nandhi Vardhan Appana
Madhav Nandhi Vardhan Appana - avatar
0
Which one i have to complete first
28th Jun 2021, 10:28 AM
Madhav Nandhi Vardhan Appana
Madhav Nandhi Vardhan Appana - avatar
0
Python core or Python intermediate
28th Jun 2021, 10:29 AM
Madhav Nandhi Vardhan Appana
Madhav Nandhi Vardhan Appana - avatar