On 2019-04-23 18:52, Terry Reedy wrote:
On 4/23/2019 2:44 AM, 林自均 wrote:
Hi all,

I found that there are str.index() and str.rindex(), but there is only list.index() and no list.rindex().

str.index and list.index are related but not the same.  The consistency
argument is better applied to find-rfind, index-rindex,
partition-rpartition, etc.

It is much more common to process strings right to left or in both
directions, than process lists right to left or in both directions.
Moreover, lists have a reverse method, strings do not.
''.join(reversed(somestring)) is likely slower, especially if there many
non-ascii chars.  Moreover, somestring.rindex(substring) would have to
have both somestring and substring reversed when substring is more than
one char.

You can reverse a string with somestring[::-1].

Personally, I'm not convinced by the "lists can be reversed" argument.

[snip]
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to