How to generate a range of lines from aa ... to zz

I am trying to create a Python program where it takes a string and displays permutations on it.

For instance.

If the user enters "[AAA] Grim", he must generate words starting with "aaa Grim", then "aab Grim", then "aac Grim" to "zzz Grim", etc. Or, if the user enters "[AA] Grim", he must generate "aa Grim", "ab Grim", "ac Grim" for "zz Grim"

Sorry for the incomprehensible title of the question. I am not sure how to state what I need without an example. :)

+1
source share
2 answers
input = '[AAA] Grim'
n = len(input.split(' ')[0]) - 2
s = input[n+2:]
a = [''.join(x)+s for x in itertools.product(string.ascii_lowercase, repeat=n)]
0
source

If I understood what you had in mind, then the following:

import re
import string
import itertools

user_in = input("Enter string: ")
p_len = user_in.index(']') - user_in.index('[')
text = user_in[user_in.index(']')+1:]
print('\n'.join([ ''.join(p) + text for p in itertools.combinations_with_replacement(string.ascii_lowercase,r=p_len-1)]))

():

Enter string: [AA] Grim
aa Grim
ab Grim
ac Grim
ad Grim
ae Grim
0

All Articles