Multiple replacement in one call [was: Give regex operations more sugar]

Just changing the subject line here, to keep things on topic Sincerely, Ken; ---------- Forwarded message --------- Date: Thu, 14 Jun 2018 17:29:03 +1000 From: Steven D'Aprano <steve@pearwood.info> To: python-ideas@python.org Subject: Re: [Python-ideas] Give regex operations more sugar Message-ID: <20180614072902.GH12683@ando.pearwood.info> Content-Type: text/plain; charset=us-ascii On Thu, Jun 14, 2018 at 06:33:14PM +1200, Greg Ewing wrote:
"Explicit is better than implicit" -- the problem with having the order be meaningful is that it opens us up to silent errors when we neglect to consider the order. replace((spam, eggs, cheese) ...) *seems* like it simply means "replace any of spam, eggs or cheese" and it is easy to forget that that the order of replacement is *sometimes* meaningful. But not always. So this is a bug magnet in waiting. So I'd rather have to explicitly specify the order with a parameter rather than implicitly according to how I happen to have built the tuple. # remove duplicates targets = tuple(set(targets)) newstring = mystring.replace(targets, replacement) That's buggy, but it doesn't look buggy, and you could test it until the cows come home and never notice the bug. -- Steve ------------------------------ Subject: Digest Footer _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas ------------------------------ End of Python-ideas Digest, Vol 139, Issue 70 *********************************************
participants (1)
-
Ken Hilton