[Python-ideas] Add single() to itertools
Joao S. O. Bueno
jsbueno at python.org.br
Tue Oct 31 08:58:30 EDT 2017
On 31 October 2017 at 10:52, Steven D'Aprano <steve at pearwood.info> wrote:
> 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__.
I know that. But then, I'd rather write it as 3-4 lines in some utils module.
So, although I was initially -1 to -0 on this suggestion, maybe it has a point.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas