This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Provide list.rindex()
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.9
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, johnlinp, rhettinger, serhiy.storchaka, vstinner, xtreak
Priority: normal Keywords: patch

Created on 2019-04-16 06:46 by johnlinp, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12851 closed johnlinp, 2019-04-16 06:55
Messages (9)
msg340312 - (view) Author: 林自均 (johnlinp) * Date: 2019-04-16 06:46
There are str.index() and str.rindex(), but there is only list.index() and no list.rindex(). It will be very handy if we provide it.
msg340314 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-04-16 07:03
That's a fairly bare-bones implementation you're providing in your PR. Such a feature would need documentation, tests, news entry. I'm not endorsing or discarding your idea, but these are the general requirements for the feature of this level.
msg340317 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-04-16 07:19
New methods to builtins generally require a python-ideas discussion. Search brings up an old discussion for rindex and rremove : https://mail.python.org/pipermail/python-ideas/2009-May/004506.html . It also would make users ask for tuple.rindex as in the linked discussion.
msg340319 - (view) Author: 林自均 (johnlinp) * Date: 2019-04-16 08:06
Hi @SilentGhost, Thank you for the feedback. The PR is only a WIP and a placeholder.

Hi @xtreak, Thank you for searching that mailing list for me. However, after reading the thread, it seems that we didn't have any conclusion on whether we should add list.rindex() or not. Did I miss something?
msg340383 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-04-17 08:38
There were known, strong use cases for str.rindex().  The list.rindex() method was intentionally omitted.  AFAICT no compelling use cases have arisen, so we should continue to leave it out.  In general, we don't grow the core APIs unnecessarily.

Thank you for the suggestion, but we should pass on this unless actual, real-world use cases arise often enough to warrant its inclusion.
msg340417 - (view) Author: 林自均 (johnlinp) * Date: 2019-04-17 16:38
Hi @rhettinger ,

Thank you for the reply. May I ask what is the known, strong use cases for str.rindex()?
msg340751 - (view) Author: 林自均 (johnlinp) * Date: 2019-04-24 01:02
From the discussion in https://mail.python.org/pipermail/python-ideas/2019-April/056416.html, Guido said:

> Some use cases for rindex() on strings that I found in a large codebase
here include searching a pathname for the final slash, a list of
comma-separated items for the last comma, a fully-qualified module name for
the last period, and some ad-hoc parsing of other things. The "last
separator" use cases are the most common and here rindex() sounds very
useful.

I guess that's strong enough.
msg340758 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-04-24 07:05
> I guess that's strong enough.

As a str.rindex use case. I don't read it as Guido's endorsing list.rindex proposal, johnlinp.
msg340762 - (view) Author: 林自均 (johnlinp) * Date: 2019-04-24 08:32
Hi @SilentGhost,

Yes, sorry I didn't make it clear. I was just posting the discussion here for some reference, not claiming that this issue should be reopened.
History
Date User Action Args
2022-04-11 14:59:14adminsetgithub: 80820
2019-04-24 08:32:51johnlinpsetmessages: + msg340762
2019-04-24 07:05:10SilentGhostsetmessages: + msg340758
2019-04-24 01:09:58vstinnersetnosy: + vstinner
2019-04-24 01:02:10johnlinpsetmessages: + msg340751
2019-04-17 16:38:47johnlinpsetmessages: + msg340417
2019-04-17 08:38:40rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg340383

stage: patch review -> resolved
2019-04-16 08:06:11johnlinpsetmessages: + msg340319
2019-04-16 07:19:19xtreaksetnosy: + xtreak
messages: + msg340317
2019-04-16 07:03:46SilentGhostsetnosy: + rhettinger, SilentGhost, serhiy.storchaka
messages: + msg340314
components: + Interpreter Core, - Library (Lib)
2019-04-16 06:55:57johnlinpsetkeywords: + patch
stage: patch review
pull_requests: + pull_request12776
2019-04-16 06:46:24johnlinpcreate