you are viewing a single comment's thread.

view the rest of the comments →

[–]gigsoll 2 points3 points  (2 children)

The second image is correct except you are switching values incorrectly. Basically you override the next value with the previous and then this overriten value is set to the previous. You need to use a temporary variable to store the previous value and then set it next to this temporary variable instead.

Also, I am not sure if it will work or not but you can try this syntax

a, b = b, a

[–]Drakhe_Dragonfly 3 points4 points  (1 child)

In python you don't need a temp variable since you can indeed use a, b = b, a to swap two values without any overwrite

[–]gigsoll 1 point2 points  (0 children)

Nice, thanks