
On Tue, 3 Dec 2019 at 12:07, Steven D'Aprano steve@pearwood.info wrote:
I'm sorry Juancarlo, it's not clear to me what *precisely* your proposal is. Are you asking for "findfirst" to be a builtin? A regex helper function? A method on regex objects? Something else?
My impression is that he was asking for a re.findfirst(...) function to give a more discoverable name to the next(re.finditer((...)) idiom.
As a single example of defining a dedicated function to replace a one-liner, I think it's marginal at best (although discoverability *is* important here). But IMO it is true that using next(some_iterator) to mean "get the first value returned" is something that's needed relatively frequently, but often overlooked by people. I'm not sure there's a good solution, though - adding an alias first() for "next() when used to get the first element" is probably overkill, and apart from dedicated syntax, it would be hard to find something much shorter than next().
Maybe it's just an education issue, people aren't sufficiently familiar with the idiom? Paul