Skip to content

Instantly share code, notes, and snippets.

@AaronFlower
Last active October 26, 2017 02:34
Show Gist options
  • Save AaronFlower/658bcc450a16f3178fbb2c4a0c4f9b83 to your computer and use it in GitHub Desktop.
Save AaronFlower/658bcc450a16f3178fbb2c4a0c4f9b83 to your computer and use it in GitHub Desktop.
Programming Pearls: Column 2, vector-rotation
def vector_rotation(str, pos):
'''Transpose concept: (A.T B.T).T = (BA) '''
l_half = str[:pos][::-1]
r_half = str[pos:][::-1]
new_str = l_half + r_half
return new_str[::-1]
s = 'abcdefgh'
print(vector_rotation(s, 2))
print(vector_rotation(s, 3))
print(vector_rotation(s, 7))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment