Skip to content

Instantly share code, notes, and snippets.

@carlessanagustin
Created February 5, 2020 04:06
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 carlessanagustin/1c8dfa6761eb74579394f17b9316fb25 to your computer and use it in GitHub Desktop.
Save carlessanagustin/1c8dfa6761eb74579394f17b9316fb25 to your computer and use it in GitHub Desktop.
Rotate string in Python
def rotateL(input,d):
Lfirst = input[0 : d]
Lsecond = input[d :]
return (Lsecond + Lfirst)
def rotateR(input,d):
Rfirst = input[0 : len(input)-d]
Rsecond = input[len(input)-d : ]
return (Rsecond + Rfirst)
print (rotateL("hello",2))
print (rotateR("hello",2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment