1

I have a two dimensional array and a one dimensional array. I need to >find the combinations of the two and add that to another array. So for >instance the two arrays a[[1,2],[3,4]] and b[5,6] I should get array >c[[1,2,5],[1,2,6],[3,4,5],[3,4,6]]. I have written code for this but >what I end up getting is c[[1,2,5,6],[1,2,5,6],[3,4,5,6],[3,4,5,6]]. I'm >a bit new to python which is why I think I'm having so many problems.

the code I have so far

b = [11, 14]
c = [[1,2,3],[2,3,4],[3,4,5],[4,5,6]]
f = []


for x in range(0, len(c)):
    d = []
    for y in range(0, len(c[0])):
        d.append(c[x][y])        
    for z in range(0, len(b)):
        e = d
        e.append(b[z])
        f.append(e)
print(f)

1 Answer 1

1

You need to use the copy() function :

e = d.copy()

Check the documentation: https://docs.python.org/3/library/copy.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.