def rotate_swap(lst, dist):
 n = len(lst)
 if ((dist == 0) or (dist == n)):
  return
 i = p = dist
 j = (n - p)
 while (i != j):
  if (i > j):
   sublist_swap(lst, (p - i), p, j)
   i -= j
  else:
   sublist_swap(lst, (p - i), ((p + j) - i), i)
   j -= i
 sublist_swap(lst, (p - i), p, i)

def rotate_swap ( lst , dist ) : n = len ( lst ) if ( ( dist == 0 ) or ( dist == n ) ) : return i = p = dist j = ( n - p ) while ( i != j ) : if ( i > j ) : sublist_swap ( lst , ( p - i ) , p , j ) i -= j else : sublist_swap ( lst , ( p - i ) , ( ( p + j ) - i ) , i ) j -= i sublist_swap ( lst , ( p - i ) , p , i )
a recursive sub-list swapping method .