I have a list :
s = ["sam1", "s'am2", "29"]
I want to replace ' from the whole list.
I need output as
s = ["sam1", "sam2", "30"]
currently I am iterating through the list.
Is there any better way to achieve it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could try this:
but as pointed out this is still iterating through the list. I can’t think of any solution that wouldn’t include some sort of iteration (explicit or implicit) of the list at some point.
If you have a lot of data you want to do this to and are concerned about speed, you could evaluate the various approaches by timing them and pick the one that’s the fastest, otherwise I would stick with the solution you consider most readable.