0
About this lesson"list operations"May I know how can we replace one letter of a string by another?
4 Answers
+ 3
Are you talking about python? To get it clear please give a sample of list, and what you are going to replace.
But anyway it is recommended to continue the lesson.
+ 3
OK so thats very simple. if you will keep the original list as it is, use a new list for result.
newlst = Name.replace(âwâ, âyâ)
(generally it is recommended to use lowercase naming for variables)
In this case all âwâ in the string will be replaced. If you only want to replace one âwâ there is a third argument:
x=input("Enter a number you want to add in the list")
newlst = Name.replace(âwâ, âyâ, 1)
this will replace the first âwâ only.
+ 1
Thanks a lot
0
A simple example
Name=["hello world"]
And I just want to replace "w" by "y" even if that doesn't have a sense