[issue34312] Allow str.endswith and str.startswith to accept an iterable

Raymond Hettinger report at bugs.python.org
Wed Aug 1 22:54:24 EDT 2018


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

ISTM that this would encourage silently inefficient coding patterns like:

   url.endswith({'.html', '.txt', '.php'})
   # The set object gets rebuilt on every call
   # and a new set iterator object gets built on every call.
   # Looping over the contents uses the slower iterator protocol
   # rather than the existing superfast PyTuple_GET_SIZE() and
   # PyTuple_GET_ITEM() macros which are entirely in-lined.

Do we have any known use cases or user requests where the existing API doesn't suffice?

----------
nosy: +rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34312>
_______________________________________


More information about the Python-bugs-list mailing list