Welcome to the Treehouse Community
Looking to learn something new?
Can some explain how this expression is evaluated in python?
Can someone explain what's going on "behind the scenes" in the below expression?
arr[i], mx = mx, max(arr[i], mx)
Take for example :
arr[i] = 5 mx = -1
So in the "first" part of the expression arr[i] gets set to -1, but what I'm having trouble grasping is why arr[i] remains 5 when evaluating the second part of the expression.
Chris FreemanTreehouse Moderator 67,989 Points
# Given arr[i] = 5 mx = -1 arr[i], mx = mx, max(arr[i], mx) # becomes arr[i], mx = -1, max(5, -1) # becomes arr[i], mx = -1, 5 # tuple on right is assigned to tuple on left # arr[i] becomes -1 # mx becomes 5
>>> arr = [0, 5, 10, 15] >>> i = 1 >>> arr[i] 5 >>> mx = -1 >>> arr[i], mx = mx, max(arr[i], mx) >>> arr [0, -1, 10, 15] >>> mx 5
Post back if you need more help. Good luck!!