(Jan-27-2021, 06:03 PM)bowlofred Wrote: Just makevariables
an iterator/list whatever of integers then. Here I just set it via range, but it could be set any way.
from itertools import product from more_itertools import grouper import string # create the "data" number_pairs = 3 variables = list(range(number_pairs * 2)) print(f"variables data starts as {variables}") number = len(variables) groups = grouper(variables, 2) finallist = product(*groups) print(list(finallist))
Output:variables data starts as [0, 1, 2, 3, 4, 5] [(0, 2, 4), (0, 2, 5), (0, 3, 4), (0, 3, 5), (1, 2, 4), (1, 2, 5), (1, 3, 4), (1, 3, 5)]
I apologise, probably it is my fault that I cannot tell what I want exactly but NO! my variables are not 0 2 4 my variables must be that
for variables in itertools.product([0, 1], repeat=(number*2))After that I should create this groups
And after that I am writing what you recommand:
number =2 for variables in itertools.product([0, 1], repeat=(number*2)): # set of variables for a,ap,b,bp,c,cp like 000000 000001 000011.... #a,ap,b,bp,c,cp= variables[0],variables[1],variables[2],hvariables[3] #giving value for a,ap,b,bp,c,cp #nlist = [(a,b),(a,bp),(ap,b),(ap,bp)] #binary combination of a,ap,b,bp,c,cp groups = grouper(variables, 2) finallist = product(*groups) print(list(finallist))And I am getting this error:
Error:raceback (most recent call last):
File "free.py", line 151, in <module>
groups = grouper(variables, 2)
File "/usr/lib/python3/dist-packages/more_itertools/recipes.py", line 295, in grouper
args = [iter(iterable)] * n
TypeError: 'int' object is not iterable
My variable is already a list !!! Why am I gettigng this error?P.S I also wrote: variable = list(variable) but still it did not work