I'm trying to replace a character in a string with all possible combinations of "ABCDEF", and create a file with all combinations.
I have the first part working but can't get it to append to the list and then write to the file.
I'd appreciate any help you can give.
import itertools
keyList = []
def replaceX(s, chars):
for element in map(iter, itertools.product(chars, repeat=s.count("X"))):
yield ''.join(char if char != 'X' else next(element) for char in s)
keyList.append(*replaceX("ABCXXABXXABCDEF\n", "ABCDEF"))
# print(*replaceX("ABCXXABXXABCDEF\n", "ABCDEF"))
print(keyList)
outFile = open("key-file.txt", "w")
outFile.writelines(keyList)
outFile.close()