Skip to content

Instantly share code, notes, and snippets.

@diversemix
Created November 2, 2020 11:26
Show Gist options
  • Save diversemix/01dfb9701c7c4981914cbe2db95ba1be to your computer and use it in GitHub Desktop.
Save diversemix/01dfb9701c7c4981914cbe2db95ba1be to your computer and use it in GitHub Desktop.
Python to rotate a string
# Given a number write a function that finds all rotations of its digits.
# For example for 197 the output would be 197, 971, and 719.
# Rotation is first diget to the moved to the end
# Last diget moved to the start
num = 1973
def rotate(num_str):
return num_str[-1] + num_str[0:-1]
num_str = str(num)
length = len(num_str)
for i in range(length):
print(num_str)
num_str = rotate(num_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment