In article <mailman.16689.1417996247.18130.python-l...@python.org>, Chris Angelico <ros...@gmail.com> wrote:
> On Mon, Dec 8, 2014 at 10:33 AM, Steven D'Aprano > <steve+comp.lang.pyt...@pearwood.info> wrote: > > How would we re-write this to work in the future Python 3.7? Unless I have > > missed something, I think we could write it like this: > > > > def myzip37(*args): > > iters = list(map(iter, args)) > > while iters: > > try: > > yield tuple([next(i) for i in iters]) > > except StopIteration: > > return I'm still not liking this use of while. Yes, of course, it handles the special case of no arguments, but I'd be in-your-face about that (not tested): def myzip37(*args): iters = list(map(iter, args)) if not iters: return None while True: try: yield tuple([next(i) for i in iters]) except StopIteration: return This makes it really obvious that there's something going on inside the loop other than exhausting the control variable to cause it to exit. Although, to be honest, I'm wondering if this is more straight-forward (also not tested): def myzip37(*args): if not args: return iters = list(map(iter, args)) while True: try: yield tuple(map(next, iters)) except StopIteration: return -- https://mail.python.org/mailman/listinfo/python-list