Stopping an iterator and continuing later

Gregory Ewing greg.ewing at canterbury.ac.nz
Sun Nov 26 17:31:35 EST 2017


november nihal wrote:
> I should have added I switch off the machine when I stop. ( I dont have options
>  to keep it in a sleep mode or in hibernation )

The iterator returned by itertools.combinations is pickleable:

 >>> from pickle import dumps, loads
 >>> from itertools import combinations
 >>> c = combinations([1,2,3,4,5], 2)
 >>> next(c)
(1, 2)
 >>> next(c)
(1, 3)
 >>> next(c)
(1, 4)
 >>> s = dumps(c)
 >>> d = loads(s)
 >>> next(d)
(1, 5)

-- 
Greg



More information about the Python-list mailing list