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??
char Array With a for Loop. We can fill a fixed size char array with our desired character and convert that to a string: char[] charArray = new char[N]; for (int i = 0; i < N; i++) { charArray[i] = 'a'; } String newString = new String(charArray); assertEquals(EXPECTED_STRING, newString);
Use a backslash ( \ ) as a line continuation character In Python, a backslash ( \ ) is a line continuation character. If a backslash is placed at the end of a line, it is considered that the line is continued on the next line.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With