On Mon, Dec 09, 2019 at 12:35:28PM -0600, Tim Peters wrote:

> I would _much_ rather write - and read:
> 
>     a = first(iterable, default)
> 
> than
> 
>     a = take(1, iterable, default)[0]
> 
> for much the same reasons I'd much rather write and read "2" than
> "int(10 / 5)" ;-)

Fair enough. If you're binding directly to a result, you can avoid the 
subscripting by using sequence unpacking, which might look nicer:

    (a,) = take(1, iterable, default)

or write your own one-liner helper :-)

I'm thinking that, given Raymond's long reluctance to add additional 
functions to itertools, it might be easier to add `take` since it is a 
strictly more powerful function than `first`. If we can only get one, 
I'd go for `take` since it can do everything `first` would do and more.



-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QXW5SCDK6R7ZDPZNO4OEE3FGAXZNOY5O/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to