import itertools as its words = 'abcd123456' r = its.product(words, repeat=6) dic = open('pass.txt', 'a') for i in r: dic.write(''.join(i) + ' ') print(i) dic.close()