On Mon, Dec 9, 2019 at 10:39 AM Tim Peters <tim.pet...@gmail.com> wrote:
> [Steven D'Aprano <st...@pearwood.info>] > > What do you think of my suggestion that we promote the itertools recipe > > "take" into a function? > > > > > https://mail.python.org/archives/list/python-ideas@python.org/message/O5RYM6ZDXEB3OAQT75IADT4YLXE25HTT/ > > That it's independent of whether `first()` should be added. > > 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)" ;-) > Ditto from me. I bumped up against calling next() recently for the first item and had to rely on the fact that I controlled the code to ignore StopIteration since it was in a small script, but I have needed just the first item so many times before and didn't want any exception to propagate out that I would have loved to have such a function instead of adding to add in a 'try' as well. -Brett > > But, as stated before, I'm not a minimalist when it comes to > itertools. In turn, I'd much rather write & read`take(n, iterable, > default) than the stuff it takes to plug in "enough" defaults, when > needed, without it. > _______________________________________________ > 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/QO75UXCOC67Y4C2PXBKXHP7P34VCVVOS/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ 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/GO74TWUDHCDWAKHBMGEUARZK3R53FTCV/ Code of Conduct: http://python.org/psf/codeofconduct/