Issue 36639: Provide list.rindex() - Python tracker (original) (raw)

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:14 admin set github: 80820
2019-04-24 08:32:51 johnlinp set messages: +
2019-04-24 07:05:10 SilentGhost set messages: +
2019-04-24 01:09:58 vstinner set nosy: + vstinner
2019-04-24 01:02:10 johnlinp set messages: +
2019-04-17 16:38:47 johnlinp set messages: +
2019-04-17 08:38:40 rhettinger set status: open -> closedresolution: rejectedmessages: + stage: patch review -> resolved
2019-04-16 08:06:11 johnlinp set messages: +
2019-04-16 07:19:19 xtreak set nosy: + xtreakmessages: +
2019-04-16 07:03:46 SilentGhost set nosy: + rhettinger, SilentGhost, serhiy.storchakamessages: + components: + Interpreter Core, - Library (Lib)
2019-04-16 06:55:57 johnlinp set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest12776>
2019-04-16 06:46:24 johnlinp create