Dec-29-2022, 11:13 AM
I have the following code :
import itertools from functools import reduce CountOfCombination= 0 for i in itertools.product((1,2),(1,2,0),(1,2)): CountOfCombination += 1 print('For combination {0} is product of values {1} and sum{2}'.format(i, reduce(lambda a, b: a*b,i),reduce(lambda a, b : a+b,i))) print ('Count of combination is {0}'.format(CountOfCombination))I would like to populate a variable for the cartesian product via user input, something like this :
import itertools cont = "" index = 0 a=[] while (cont != "N"): tips = input("Input combination : ") for i in range(len(tips)): a[index][i] = tips[i] index += 1 cont = input("Contiune? [Y/N]")where a[] would replace
(1,2),(1,2,0),(1,2)