This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients apalala, ezio.melotti, mrabarnett, rhettinger, serhiy.storchaka, terry.reedy
Date 2020-01-04.13:14:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1578143670.94.0.954189337683.issue39165@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-01-04 13:14:31serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, terry.reedy, ezio.melotti, mrabarnett, apalala
2020-01-04 13:14:30serhiy.storchakasetmessageid: <1578143670.94.0.954189337683.issue39165@roundup.psfhosted.org>
2020-01-04 13:14:30serhiy.storchakalinkissue39165 messages
2020-01-04 13:14:30serhiy.storchakacreate