I am trying to replace substrings to nothing. For example, I want to convert £1,000.90 to 1000.90 i.e. simply replace '£' and ',' with nothing.
And I thought I will do this using the inline for loop.
s = '£1,000.90'
replaceStrings = ['£', ',']
s = (s.replace(x, '') for x in replaceStrings)
print(s)
But it doesn't work.
I find many alternatives to get this done, but I thought I'll try with the inline for loop.
Edit:
The answers are interesting. What is the simplest of way of replacing a list of characters to something else. Same example mentioned below. I have a list in replaceStrings. They must be removed/replaced with Empty/x from the source string s.
s = '£1,000.90'
replaceStrings = ['£', ',']
replaceStrings, it doesn't combine them. Use an ordinary loop.re.sub()if you want to replace multiple strings with the same thing.*_, s = ((s := s.replace(x, '')) for x in replaceStrings)