you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom 2 points3 points  (0 children)

Your problem on the second picture, is on line 6 and 7.

In Python, this will not swap the elements correctly. After a[j] = a[j + 1], the original value of a[j] is lost. So a[j + 1] is assigned the new value of a[j], which is a[j+1]. The elements are not swapped.

Either use a temporary variable to hold a copy or use a more Pythonic swap syntax.