i came up with this at first

Code: Select all

`for i in xrange(0,len(nums)-1):`

for j,k in itertools.combinations(nums,2):

for op in oplist:

nums.remove(j)

nums.remove(k)

nums.append(op(j,k))

but of course it won't work because i was modifying nums

then i tried this which still doesn't work for the same problem

Code: Select all

`#4 numbers in nums`

for a, b, in itertools.combinations(nums,2):

for op1 in oplist:

nums.remove(a)

nums.remove(b)

nums.append(op1(a,b)) #3 numbers in list

for c, d, in itertools.combinations(nums,2):

for op2 in oplist:

nums.remove(d)

nums.remove(c)

nums.append(op2(d,c) #2 in list

for e, f in itertools.combinations(nums,2):#there is only one possible combination.

for op3 in oplist:

nums.remove(e)

nums.remove(f)

nums.append(op3(e,f))#1 in list

and is also completely impractical if i have something like 20 numbers

the problem is that by removing and appending values to nums, i change it so that the next loop will encounter the wrong list of numbers. i can duplicate nums, but it seems wherever i do so will change nothing.

what is the typical way of iterating like this?