15,920,513 members
See more:
given two arrays I'm trying to get all the different combinations of the arrays with no repeats of sequences and without using itertools. My problem comes when I try to combine a 2 dimensional array with a 1 dimensional array. given arrays [1,2],[1,3],[1,4],[2,3],[2,4] and [1,2,3,4] I want it to yield [1,2,3],[1,2,4],[1,3,4],[2,3,4]. currently it will produce [1,2,3], [1,2,4] and [1,3,4] but not [2,3,4] and I can't figure out why.

What I have tried:

Python
```change_array = [1,2],[1,3],[1,4],[2,3],[2,4]
base_array = [1,2,3,4]
save_array = []

def candidate_generation2(change_array, base_array, save_array):
current_iteration = []
for x in range(0, len(change_array)):
d = []
for y in range(0, len(change_array[0])):
d.append(change_array[x][y])
for z in range(x + 1, len(base_array)):
e = d.copy()
tag = 0
for a in range(0, len(e)):
if e[a] == base_array[z]:
tag = 1
if tag == 0:
e.append(base_array[z])
save_array.append(e)
current_iteration.append(e)
chenge_array = current_iteration.copy()

candidate_generation2(change_array, base_array, save_array)
print(save_array)<pre>```

thanks in advance for any help
Posted
Updated 28-Oct-22 20:23pm
v3

## Solution 1

You need to define the rules for changing. At a guess from looking at your desired results you need to check each entry in the first array. Then find all values in base array larger than its largest number. Create the new three element array from that and continue until all have been processed.

Try this:
Python
```change_array = [1,2],[1,3],[1,4],[2,3],[2,4]
base_array = [1,2,3,4]
save_array = []
for ca in change_array:     # loop through all entries
highest = ca[1]         # get the last value in the item
for bav in base_array:  # check all base values
if bav > highest:   # if it is higher
cp = ca[:2]     # take a copy of the original item
cp.append(bav)  # append the new highest number
save_array.append(cp) # save the modified element
print(save_array)```