How we are amending the original list object inside the for loop

My Code

for each_row in moma:
    nationality = each_row[2]
    nationality = nationality.replace("(","")
    nationality = nationality.replace(")","")
    each_row[2] = nationality
    gender = each_row[5]
    gender = gender.replace("(","")
    gender = gender.replace(")","")
    each_row[5] = gender

So my understanding is
moma is list object.
each_row is temp variable

So we are updating ‘each_row’ variable
each_row[5] = gender and each_row[5] = gender

how the moma main list object is getting updated here?

hey @hulesameer1149

Welcome to DataQuest community!

each_row in for loop is like - at a time work on 1 row, and with every loop, the rows will change sequentially.

that is in 1st loop it will work on row1 then 2nd loop row2 and so on… till all the rows are worked upon by the code one by one.

when the code reads the statement: each_row[2] = nationality and each_row[5] = gender it re-assigns the updated value to the 3rd elemnt (at index 2) and 6th element (at index 5) in moma one row at a time.

for a more technical reference, please read this post. @hanqi has explained it here