Armin <feng.sh...@gmail.com> wrote: > Could you give an example of next() with a sentinel and describe its > use case please? I have a little trouble understanding what you guys > mean!
It means you don't have to worry about next() throwing StopIteration. e.g. >>> def pairs(sequence, padding=None): sequence = iter(sequence) for a in sequence: b = next(sequence, padding) yield a, b >>> list(pairs('abcd')) [('a', 'b'), ('c', 'd')] >>> list(pairs('abcde')) [('a', 'b'), ('c', 'd'), ('e', None)] -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list