On Dec 5, 2019, at 08:53, Juancarlo Añez <apal...@gmail.com> wrote:
> 
> 
> The proposed implementation of a findfirst() would handle many common cases, 
> and be friendly to newcomers (why do I need to deal with a Match object?), 
> specially if the semantics are those of findall():
> 
>      next(iter(findall(...)), default=default)

The problem with using findall instead of finditer or search is that it scans 
the whole document rather than just until the first match, and it builds a 
potentially huge list just to throw it away. It’s pretty common that one or 
both of those will be a serious performance issue. Imagine asking to find the 
first double consonant in the OED and it takes a minute to run and pins a 
gigabyte of memory.

It’s unfortunate that these functions aren’t better matched. Why is there a 
simple-semantics find-everything and a match-semantics find-iteratively and 
find-one? But I don’t think adding a simple-semantics find-one that works by 
inefficiently finding all is the right solution.

And if the point of proposing first is that novices will figure out how to 
write first(findall(…)) so we don’t need to add findfirst, then I think we need 
findfirst even more, because novices shouldn’t learn that bad idea.

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7ZBFVVVVNY6I74V2DBONGSCHDEDVKHNU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to