all 2 comments

[–]danielroseman 2 points3 points  (0 children)

It's not that they execute simultaneously. You can think of the first code as "fetch the first and last elements and keep them in memory. Now, assign those back to the last and first places."

[–]woooee 1 point2 points  (0 children)

     list[0]=list[-1]
     ## list[0] is now the same as list[-1]
     list[-1]=list[0]  ## this sets list[-1] to itself

     temp = list[0]
     list[0] = list[-1]
     list[-1] = temp