On 2 May 2005 21:49:33 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote:
>Starting from Python 2.4 we have tee in the itertools >module, so you can define the following: > >from itertools import tee > >def is_empty(it): > it_copy = tee(it)[1] > try: > it_copy.next() > except StopIteration: > return True > else: > return False > >It works with generic iterables too. Are you sure this is going to do the right thing ? seems to me it would drop the first element of "it"... (the yielded element entered the tee twins, but already got out of "it"). I would say that unless you use the second twin after calling is_empty that code wouldn't work... Am I correct or instead "tee" uses black magic to just peek at the yielded value without starting a continuation ? Andrea -- http://mail.python.org/mailman/listinfo/python-list