Generating character permutations I want to generate a 'dictionary' containing all 8 character permutations of upper-case letters such that the output file looks like:

AAAAAAAA
AAAAAAAB
AAAAAAAC
...
ZZZZZZZZ


I came up with this solution that uses the product method of itertools:

from itertools import product

per = product('ABCDEFGHIJKLMNOPQRSTUVWXYZ', repeat=8)

f = open('myfile', 'w')

p = ""

for p in per:
    p = "".join(p)
    f.write(p + "\n")

f.close()


I know there's 208,827,064,576 (> 200 billion) possible permutations so it's going to take time no matter what, but how can I optimise this?
Not much to do there, maybe use with ... as and inline everything:

from itertools import product

with open('myfile', 'w') as file:
    for p in product('ABCDEFGHIJKLMNOPQRSTUVWXYZ', repeat=8):
        file.write("".join(p) + "\n")


I'm sure there is a clever way to generate the characters as well. Edit: ah yes, you could replace 'A...Z' with map(chr, range(65, 91)) although
that seems rather cryptic.

Now why would you want that though? It seems that using that generator and
staying in Python would be more than enough instead of generating a static
file.