Python “int is not subscriptable” error val, j = 0[i], i-1 Edit this line and try this instead – val, j = a[i], i-1