5

I want to generate, in python (without a dictionary), a list of string from aaa-zzz and then output a txtfile such as this (note, the ... is short for the strings in between):

aaa
aab
aac
aad
...
aaz
aba
abb
abc
abd
...
aaz
...
zaa
...
zzy
zzz

The harder challenge is to genrate alternating (upper and lower) strings. How to generate these?

aaa
...
aaz
aaA
...
aaZ
aba
...
abz
...
abA
...
abZ
aBa
...
aBz
aBA
...
aBZ
...
zzz
zzA
...
...
zzZ
zAa
...
zAz
...
zZa
...
zZz
...
...
ZZZ

Just a bonus question, is there a way to not only include a-z, A-Z but also 0-9 in the generation??

alvas
  • 115,346
  • 109
  • 446
  • 738

1 Answers1

27
import itertools, string

map(''.join, itertools.product(string.ascii_lowercase, repeat=3))
map(''.join, itertools.product(string.ascii_letters, repeat=3))
map(''.join, itertools.product(string.ascii_letters + string.digits, repeat=3))
ecatmur
  • 152,476
  • 27
  • 293
  • 366