[Python-ideas] What are the strong use cases for str.rindex()? (John Lin)
Steven D'Aprano
steve at pearwood.info
Thu Apr 25 03:57:02 EDT 2019
On Wed, Apr 24, 2019 at 01:50:48AM +0800, Thautwarm Zhao wrote:
> However, the reason why we don't need list.rindex but do for str.rindex is
> simple I'd say: str is immutable and has no O(1) reverse method.
>
> On the other hand, when it comes to list, you can use list.index after
> list.reverse, and after a bunch of operations you can resume the state by
> invoking list.reverse again.
list reverse is not O(1), and flipping the order, then flipping the
order back again is not safe if the list could be accessed by two or
more threads.
(The call to reverse itself is thread-safe, but not the operations in
between.)
--
Steven
More information about the Python-ideas
mailing list