[docs] A bug in Python v2.6.6 documentation
Jakub Kowalski
j.kowalski at nencki.gov.pl
Fri Apr 1 10:56:31 CEST 2011
Hello,
I have found a bug in the chapter 9.7.1. Itertool functions:
product(A, B) is not equivalent to ((x,y) for x in A for y in B)
It is untrue for dependent iterators - and here is the proof:
>>> class c:
... def g(self):
... for i in xrange(self.x):
... yield i
... def h(self, x):
... for i in xrange(x):
... self.x = i
... yield i
>>> for i in ((x, y) for x in d.h(4) for y in d.g()):
... print i
(1, 0)
(2, 0)
(2, 1)
(3, 0)
(3, 1)
(3, 2)
>>> for i in product(d.h(4), d.g()):
... print i
(0, 0)
(0, 1)
(0, 2)
(1, 0)
(1, 1)
(1, 2)
(2, 0)
(2, 1)
(2, 2)
(3, 0)
(3, 1)
(3, 2)
Greetings, J.Kowalski
More information about the docs
mailing list