Skip to content

Instantly share code, notes, and snippets.

@aconbere
Forked from zane/rotate.py
Created January 15, 2010 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aconbere/278432 to your computer and use it in GitHub Desktop.
Save aconbere/278432 to your computer and use it in GitHub Desktop.
removing temp variable
import math
def rotate(array, steps):
steps = steps % len(array)
reverse(array, 0, len(array) - 1)
reverse(array, 0, steps - 1)
reverse(array, steps, len(array) - 1)
return array
def reverse(array, start=0, end=None):
if end is None:
end = len(array) - 1
for x in range((end - start) / 2):
array[start + x], array[end - x] = array[end - x], array[start + x]
return array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment