|
From: Armin Ronacher <armin.ronacher <at> active-4.com>
Subject: Confusing listreverseiterator Behavior Newsgroups: gmane.comp.python.devel Date: 2008-08-26 19:05:19 GMT (44 weeks, 5 days, 2 hours and 51 minutes ago) Hi, I stumbled upon a confusing listreverseiterator behavior: >>> l = [1, 2, 3, 4] >>> i = iter(l) >>> ri = reversed(l) >>> len(i) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: object of type 'listiterator' has no len() >>> len(ri) 4 >>> ri.next() 4 >>> len(ri) 3 This is the only reverse iterator with that sort of behavior. Is that intentional if yes, why? I stumbled upon that when writing a templating engine that tried to lazily get the length of the sequence / iterator but failed doing so after the first iteration because the length of the reverse iterator changes every iteration. Regards, Armin _______________________________________________ Python-Dev mailing list Python-Dev <at> python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-python-dev%40m.gmane.org |
|
|