Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

Your implementation takes several lines of code only because of complex 
semantic of findall() which you want to preserve in findfirst(). Actually 
findall() is an equivalent of one of three expressions, depending on the number 
of capturing groups in the regular expression:

    [m[0] for m in finditer(...)]
    [m[1] for m in finditer(...)]
    [m.groups() for m in finditer(...)]

so findfirst() is an equivalent of one of three expressions:

    search(...)[0]
    search(...)[1]
    search(...).groups()

In real code the number of capturing groups in the regular expression you use 
is known statically, so you should not dispatch one of above variants at run 
time. You just use the appropriate one.

findall() is older interface. More modern, generator and object interface is 
finditer(). findall() was not deprecated and was not converted to returning an 
iterator because many old code uses it, and we do not want to break it.

----------

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

Reply via email to