def rotate_juggle(lst, dist):
 n = len(lst)
 for i in xrange(gcd(dist, n)):
  t = lst[i]
  j = i
  while 1:
   k = ((j + dist) % n)
   if (k == i):
    break
   lst[j] = lst[k]
   j = k
  lst[j] = t

def rotate_juggle ( lst , dist ) : n = len ( lst ) for i in xrange ( gcd ( dist , n ) ) : t = lst [ i ] j = i while 1 : k = ( ( j + dist ) % n ) if ( k == i ) : break lst [ j ] = lst [ k ] j = k lst [ j ] = t
an iterative juggle method .