12 73 2876 2755 28 127 847 25 551 37 898 14 29 cur_buf for in for in x

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
A = [12, 73, 2876, 2755, 28, 9, 127, 847, 25, 551, 37, 898, 14, 29]
cur_buf = 0
for i in [0, 1, 2, 3, 4]:
for j in xrange(len(A)):
if A[j] % 5 == i:
A[j], A[cur_buf] = A[cur_buf], A[j]
cur_buf += 1
print A
print map(lambda x: x % 5, A)