Rémi Lapeyre <remi.lape...@henki.fr> 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 have two versions of the same method, one that raises an 
exception on error and one that returns a sentinel, most only have the one that 
raises.


Notice that your example is not simpler with your proposal:

# Example driver code:
index = find(list, possible_element)
if index_of_element == -1:
    pass # Not found
else:
    pass # Found


is a hard to read than and actually longer:

try:
    index = list.index(possible_element)
except ValueError:
    index = -1

if you really care about the number of lines you could use, while I don't 
recommend it:

try: index = list.index(possible_element)
except ValueErrort: index = -1

Also adding a new method to list would mean adding it to all sequence objects 
and that is asking for a lot.

----------
nosy: +remi.lapeyre

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40531>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to