[issue40531] Adding the method find() to list

2020-05-06 Thread João Marcos
João Marcos added the comment: Thanks for the replies!. Here's the link for discussion in the Python Ideas: https://discuss.python.org/t/adding-the-method-find-to-list/4113 -- ___ Python tracker

[issue40531] Adding the method find() to list

2020-05-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: Please take this to Python ideas. My understanding is that index() is supposed to be the one-way-to-do-it going forward. The find() API proved to be problematic because -1 is a valid index and people were hitting bugs by failing to check for the -1 and

[issue40531] Adding the method find() to list

2020-05-06 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: Hi João, ideas like this can also be proposed first on the python-ideas mailing list but as you said in your post there is already a method to do this and it raises ValueError when it is not found which is a common idiom in Python. Other objects don't often hav

[issue40531] Adding the method find() to list

2020-05-06 Thread João Marcos
João Marcos added the comment: This is my first issue, is this the right place to discuss enhancements? -- components: +Library (Lib) ___ Python tracker ___ ___

[issue40531] Adding the method find() to list

2020-05-06 Thread João Marcos
New submission from João Marcos : """ PROBLEM: When trying to search the position of an element inside a list, we should use the `in` operator to first check if the element exists, and then use the `index` method to obtain the index. `in` (__contains__) runs a linear search to return the bool