Question: (PYTHON 3.8) Let's assume I have a list, in which I have two items, both of which are list themselves(without knowing how many integers in

(PYTHON 3.8)

Let's assume I have a list, in which I have two items, both of which are list themselves(without knowing how many integers in each list, but they are the same length).

For example:

main_list = [[1,2,3],[4,5,6]]

main_list[0] = [1,2,3]

main_list[1] = [4,5,6]

how can I perform operations (take addition for example) on the inner lists to their matching indexes by altering the inner lists but not removing them from main_list(temporary variables are fine)

(main_list[0])[0] += (main_list[1])[0]

(main_list[0])[1] += (main_list[1])[1]

(main_list[0])[2] += (main_list[1])[2]

...and so on, using a loop, I can't hardcode it as i don't know the length of the lists(though I do know they are the same length)

to make main_list[0] = [5,7,9]

and main_list[1] stays the same

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!