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