On Mon, Oct 24, 2016 at 5:56 PM, Chris Angelico
On Tue, Oct 25, 2016 at 4:48 AM, Chris Barker
wrote: On Mon, Oct 24, 2016 at 8:21 AM, Michel Desmoulin
wrote: This actually could be implemented directly in str.replace() without breaking the API by accepting:
"stuff".replace('a', '') "stuff".replace(('a', 'b', 'c'), '') "stuff".replace(('a', 'b', 'c'), ('?', '*', ''))
+1 -- I have found I Need to do this often enough that I've wondered why it's not there.
making three calls to replace() isn't too bad, but is klunky and has performance issues.
And it may not be semantically identical. In the examples above, three separate replace calls would work, but a syntax like this ought to be capable of an exchange - "aabbccdd".replace(('b', 'd'), ('d', 'b')) == "aaddccbb".
What would be the expected behavior of "aabbccdd".replace(('a', 'aa'), ('x', 'y'))? It's not obvious to me whether longer replacement strings ('aa') or earlier replacement strings ('a') should take priority. Or is the proposal to only support this for replacements of single characters? Nathan
ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/