New submission from Phil Connell: A recipe often requested on the likes of stackoverflow and activestate is a way to look 'ahead' in an iterator, without altering the values returned for subsequent next() calls.
Last time this came up on python-ideas, it got a reasonable reception: http://code.activestate.com/lists/python-ideas/19509/ So, having wanted (and implemented) this again, I thought it was worth a formal proposal. Is this an idea worth pursuing? I've attached a quick pure Python implementation, that adds a 'peek' method, used like this: >>> it = lookahead(range(10)) >>> next(it) 0 >>> it.peek() 1 >>> next(it) 1 >>> it.peek(index=1) 3 >>> it.peek() 2 >>> next(it) 2 ---------- components: Library (Lib) files: lookahead.py messages: 185527 nosy: pconnell, rhettinger, terry.reedy priority: normal severity: normal status: open title: Add lookahead/peek wrapper to itertools type: enhancement versions: Python 3.4 Added file: http://bugs.python.org/file29606/lookahead.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17577> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com