On Jan 22, 1:19 pm, Alan Isaac <[EMAIL PROTECTED]> wrote:
[...]
> PS My understanding is that the behavior
> of the last is implementation dependent
> and not guaranteed.
[...]
> def pairs4(x):
>     xiter = iter(x)
>     for x12 in izip(xiter,xiter):
>         yield x12

According to the docs [1], izip is defined to be equivalent to:

     def izip(*iterables):
         iterables = map(iter, iterables)
         while iterables:
             result = [it.next() for it in iterables]
             yield tuple(result)

This guarantees that it.next() will be performed from left to right,
so there is no risk that e.g. pairs4([1, 2, 3, 4]) returns [(2, 1),
(4, 3)].

Is there anything else that I am overlooking?

[1] http://docs.python.org/lib/itertools-functions.html

--
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to