
July 24, 2016
3:07 a.m.
On Sun, Jul 24, 2016 at 09:48:44AM +1000, Chris Angelico wrote:
On Sun, Jul 24, 2016 at 2:57 AM, Serhiy Storchaka <storchaka@gmail.com> wrote:
There is such a protocol. Use copy.copy().
Time machine strikes again! Restarting of iterators exists.
You can copy *some* iterators, but it doesn't restart them. py> import copy py> it = iter([1, 2, 3]) py> next(it) 1 py> next(it) 2 py> a = copy.copy(it) py> next(a) 3 py> next(it) 3 I wouldn't expect that copying an iterator would, in general, restart it. In general, there's no way to restart an iterator. Once seen, values are gone and cannot be recreated. -- Steve