I’m using python to generate combinations of 2 strings and I want the first string to generate numbers 0-2^200 only going up from 0 without printing the same combinations of the same number of this string, while the second string in the iterable generates all combinations normally of the strings “01234”.
My code so far is:
import itertools
# Create a generator for combinations
def generate_combinations():
numbers = range(2**256) # This is a very large range
for number in numbers:
for combination in itertools.product([number], "01234", repeat=4):
yield combination
# Use the generator to get combinations one at a time
combinations_generator = generate_combinations()
# Process combinations one at a time
for i, combination in enumerate(combinations_generator):
print(combination)
The output I am getting is (I just skipped to a random iteration):
0, ‘0’, 0, ‘0’, 0, ‘0’, 0, ‘0’)
(0, ‘0’, 0, ‘0’, 0, ‘0’, 0, ‘1’)
(0, ‘0’, 0, ‘0’, 0, ‘0’, 0, ‘2’)
(0, ‘0’, 0, ‘0’, 0, ‘0’, 0, ‘3’)
(0, ‘0’, 0, ‘0’, 0, ‘0’, 0, ‘4’)
(0, ‘0’, 0, ‘0’, 0, ‘1’, 0, ‘0’)
(0, ‘0’, 0, ‘0’, 0, ‘1’, 0, ‘1’)
(0, ‘0’, 0, ‘0’, 0, ‘1’, 0, ‘2’)
(0, ‘0’, 0, ‘0’, 0, ‘1’, 0, ‘3’)
(0, ‘0’, 0, ‘0’, 0, ‘1’, 0, ‘4’)
(0, ‘0’, 0, ‘0’, 0, ‘2’, 0, ‘0’)
(0, ‘0’, 0, ‘0’, 0, ‘2’, 0, ‘1’)
(0, ‘0’, 0, ‘0’, 0, ‘2’, 0, ‘2’)
(0, ‘0’, 0, ‘0’, 0, ‘2’, 0, ‘3’)
(0, ‘0’, 0, ‘0’, 0, ‘2’, 0, ‘4’)
See how it generates combinations of 0 so many times? I only want the combination for 0 to be generated once. I want it like this:
0, ‘0’, 0, ‘0’, 0, ‘0’, 0, ‘0’)
(1, ‘1’, 1, ‘1’, 1, ‘1’, 1, ‘1’)
(2, ‘2’, 2, ‘2’, 2, ‘2’, 2, ‘2’)
(3, ‘3’, 3, ‘3’, 3, ‘3’, 3, ‘3’)
The number in range() iterates up by 1 each iteration while the string 01234 stays the same and generates up by 1 as you can see by the last numbers.