Of course. But if you want last(), why not just spell the utility function as I did? I.e. as a function:
def last(it): for item in it: pass return item That works fine for any iteratable (including a list, array, etc), whether or not it's a reduction/accumulation. On Oct 23, 2016 8:29 AM, "Danilo J. S. Bellini" <danilo.bell...@gmail.com> wrote: > What is `last(inf_iter)`. E.g `last(count())`. > > The "last" is just a helper function that gets the last value of an > iterable. On sequences, it can be written to get the item at index -1 to > avoid traversing it. Using it on endless iterables makes no sense. > > This makes it clear that is the users job to make sure `it` terminates. > > If one call "last" for something that doesn't terminate, an "endless" > iterable, well, it's pretty obvious that it won't "end" nicely. It's not > the Python job to solve the Entscheidungsproblem. If you call "sorted" on > endless iterables, it would behave like "last", doesn't it? > > The whole point of this idea is the scan as a generator expression or > list/set comprehension that can access the previous iteration output. > Reduce/fold is just the last value of a scan, and the scan is still defined > when there's no "last value". > > -- > Danilo J. S. Bellini > --------------- > "*It is not our business to set up prohibitions, but to arrive at > conventions.*" (R. Carnap) >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/