How to create a continuous line?

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

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

A more difficult task is to generate alternating (upper and lower) lines. How to create them?

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 az, AZ, but also 0-9 in the generation

+5
source share
1 answer
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))
+27
source

All Articles