-6

I have two lists. I want to replace J[0][0] with Leftover[0]. I present the current and expected outputs.

Leftover = [1]
J = [[0, 0, 7, 9, 10]]

for i in range(len(J)):
    J[0][Leftover[0]] = 1

print(J)

The current output is

[[0, 1, 7, 9, 10]]

The expected output is

[[1,0,7,9,10]]
2
  • 2
    J[0][0] = Leftover[0]? and why do you have a loop? Commented May 18, 2023 at 6:38
  • Does this answer your question? Replacing elements in a list, Python Commented May 22, 2023 at 20:21

1 Answer 1

1

You do not need to use a loop for doing this :)

Leftover = [1]
J = [[0, 0, 7, 9, 10]]

J[0][0] = Leftover[0]
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.