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) *  |
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) *  |
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) *  |
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) *  |
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. |
|
|