I need all possible combinations of upper words and digits in this format digit-word-word-word . I tried this code :
upper_a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
all = num + upper_a
def recursive_product(myList, length, myString = ""):
if length == 0:
print (myString)
with open('TDH-H.txt', 'a') as the_file:
the_file.writelines('{}\n'.format('TDH-H' + str(myString)))
return
for c in myList:
recursive_product(myList, length-1, myString + c)
for r in range(4, 5):
code = recursive_product(all, r)`
But it doesn't give me the format I want (dwww). What should I do ?
Try this (assuming you want combinations such as 1ABC):
from itertools import combinations, product
lc = product(num, combinations(upper_a, 3))
for x in lc:
s = x[0] + ''.join(x[1])
print(s)