On Oct 14, 6:36 am, Peter Otten <__pete...@web.de> wrote: > * I would recommend that you avoid the above approach. Pythonic solutions > favour EAFP (http://docs.python.org/glossary.html#term-eafp) over look- > before-you-leap: > > try: > value = next(y) > except StopIteration: > print "ran out of values" > else: > do_something_with(value) > > or > > value = next(y, default)
Good idea but not always convenient. Sometimes you have to perform some setup ahead of time if there are any items, and must not perform that setup if the there are no items. It's a PITA to use EAFP for that, which is why an iterator that consumes and caches can be a useful thing. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list