I need to create all combinations of the terms in a list. I've tried using all the parts of itertools
, such as permutations
, combinations
, combinations_with_replacement
, but all of them seem to almost 'count' up. For example, using this code:
from itertools import combinations_with_replacement
hex_chars = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
perm = combinations_with_replacement(hex_chars, 5)
for i in list(perm):
print(i)
It produces:
('0', '0', '0', '0', '0')
('0', '0', '0', '0', '1')
('0', '0', '0', '0', '2')
('0', '0', '0', '0', '3')
('0', '0', '0', '0', '4')
('0', '0', '0', '0', '5')
('0', '0', '0', '0', '6')
('0', '0', '0', '0', '7')
('0', '0', '0', '0', '8')
('0', '0', '0', '0', '9')
('0', '0', '0', '0', 'a')
('0', '0', '0', '0', 'b')
('0', '0', '0', '0', 'c')
('0', '0', '0', '0', 'd')
('0', '0', '0', '0', 'e')
('0', '0', '0', '0', 'f')
('0', '0', '0', '1', '1')
I need it to produce literally every possible combination, for example, you'll notice it doesn't produce "000010", and if left for long enough, it won't produce strings such as "A000A". I need to produce all of the combinations (including duplicates) that have a string-length of 5, and then I need to save them all to external text file. And, to clarify, I mean literally every single possible combination, such as "A0000", "0A000", "00A00", "000A00", "0000A0", "00000A".