[Python-ideas] Add single() to itertools
Steven D'Aprano
steve at pearwood.info
Tue Oct 31 08:52:31 EDT 2017
On Tue, Oct 31, 2017 at 10:42:23AM -0200, Joao S. O. Bueno wrote:
> When I need something like this, I usually rop a line on the module
> namespace that goes like:
>
> first = lambda x: next(iter(x))
That doesn't meet the requirement that x has ONLY one item.
And using lambda like that is bad style. This would be better:
def first(x): return next(iter(x))
and now first has a proper __name__.
--
Steve
More information about the Python-ideas
mailing list