On Sun, Jun 19, 2022 at 11:03:45PM -0700, Jeremiah Paige wrote: > What if next grew a new argument? Changing the signature of a builtin is a > big change, but surely not bigger than new syntax? If we could ask for the > number of items returned the original example might look like > > >>> first, second = next(iter(items), count=2)
There are times where "Not everything needs to be a one liner" applies. # You can skip the first line if you know items is already an iterator. it = iter(items) first, second, third = (next(it) for i in range(3)) That's crying out to be made into a helper function. Otherwise our one-liner is: # Its okay to hate me for this :-) first, second, third = (lambda obj: (it:=iter(obj)) and (next(it) for i in range(3)))(items) But that's basically islice. So: # Its okay to put reusable helper functions in a module. # Not everything has to be syntax. first, second, third = itertools.islice(items, 3) I think that we have a working solution for this problem; the only argument is whether or not that problem is common enough, or special enough, or the solution clunky enough, to justify a syntax solution. -- Steve _______________________________________________ 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/3G4VAU3UWM7OXUO2VRYM2I2BKZBIHBIW/ Code of Conduct: http://python.org/psf/codeofconduct/