For example I would like to have:
a
.
.
.
z
aa
ab
.
.
.
az
bz
.
.
.
zz
aaa
and so on.
Currently I’m here but I am lost. So feel free to propose a completely different solution.
count = 0
string = ''
for i in range(100):
count += 1
if i % 26 == 0:
count = 0
string += 'a'
ch = 'a'
x = chr(ord(ch) + count)
string = string[:-1] + x
print(i + 1, string)
and my output is something like this:
1 a
2 b
.
.
.
26 z
27 za
28 zb
.
.
.
52 zz
53 zza
54 zzb
.
.
.
>Solution :
Maybe try something like the following:
range(97,123) simply creates a range of numbers from 97 to 122, which converted to ASCII equates to a…z (done using chr())
So all our FUnction does, is it recieves a base string (starts with empty), prints out the base + range of charachters and calls its self with base + every charachter as the new base and depth decremented by 1
def printcharachters(base, depth):
if depth > 0:
for a in range(97, 123):
print(base + chr(a))
for a in range(97, 123):
printcharachters(base + chr(a), depth - 1)
printcharachters("", 2)
Replace the depth with your desired depth (for 2 the last string would be zz for 4 it would be zzzz).