
On Sat., 28 Mar. 2020, 8:39 am Guido van Rossum, <guido@python.org> wrote:
On Fri, Mar 27, 2020 at 3:29 PM Dennis Sweeney < sweeney.dennis650@gmail.com> wrote:
If I saw that in a code review I'd flag it for non-obviousness. One should use 'string != new_string' unless there is severe pressure to squeeze every nanosecond out of this particular code (and it better be inside an inner loop).
I thought that someone had suggested that such things go in the PEP,
I'm sure someone did.
I think that may have been me in a tangent thread where folks were worried about O(N) checks on long strings. I know at least I temporarily forgot to account for string equality checks starting with a few O(1) checks to speed up common cases (IIRC: identity, length, first code point, last code point), which means explicitly calling len() is just as likely to slow things down as it is to speed them up. Cheers, Nick.