Skip to content

Instantly share code, notes, and snippets.

@daniel-woods
Created April 11, 2019 19:31
Show Gist options
  • Save daniel-woods/db96c351da9ce8c4d5a6af6c2cbee19e to your computer and use it in GitHub Desktop.
Save daniel-woods/db96c351da9ce8c4d5a6af6c2cbee19e to your computer and use it in GitHub Desktop.
Shifting an inputted list by an offset
def myfnc(l, n):
le = len(l)
return l[n % le::] + l[:n % le:]
def main():
input_list = [1, 2, 3, 4, 5]
shift_rotate = 2
x = myfnc(input_list, shift_rotate)
print(x)
if __name__ == '__main__':
main()
@daniel-woods
Copy link
Author

$ python shift_list.py
[3, 4, 5, 1, 2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment