python list generation/saving bug
Question: I am trying to make program that prints all the possible combinations for `a`
to `zzz`. I tried to add a save state feature, and it works fine but there is
this bug.

Let's say I interrupted the program when it printed something like `e`. When I
execute the program again, it works fine until `z` but after `z` instead of
printing `aa` it prints `ba` and continues from `ba`. This happens right after
it prints `zz` too. it prints `baa` instead of `aaa`. How can I fix this?

Here is what I did so far:

    
    
     import pickle,os,time
    
     alphabet="abcdefghijklmnopqrstuvwxyz"
     try:
         if os.path.isfile("save.pickle")==True:
             with open("save.pickle","rb") as f:
                 tryn=pickle.load(f)
             for i in range(3):
                 a=[x for x in alphabet]
                 for j in range(i):
                     a=[x+i for x in alphabet for i in a]
                 b=a[tryn:]
                 for k in b:
                     print(k)
                     time.sleep(0.01)
                     tryn+=1
         else:
             tryn=0
             for i in range(3):
                 a=[x for x in alphabet]
                 for j in range(i):
                     a=[x+i for x in alphabet for i in a]
                 for k in a:
                     print(k)
                     tryn+=1
                     time.sleep(0.01)
     except KeyboardInterrupt:
         with open("save.pickle","wb") as f:
             pickle.dump(tryn,f)
    


Answer: If you're using python2, or python3 as the tag suggests, this exists in the
standard library already. See itertools, [product
py2](http://docs.python.org/2/library/itertools.html#itertools.product), and
[product
py3](http://docs.python.org/3/library/itertools.html#itertools.product), for a
simple way to solve this problem.

