Skip to content

Instantly share code, notes, and snippets.

@samuelbalogh
Last active September 12, 2016 10:07
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 samuelbalogh/5084aa26d39f2d1d286f3051cf00a02d to your computer and use it in GitHub Desktop.
Save samuelbalogh/5084aa26d39f2d1d286f3051cf00a02d to your computer and use it in GitHub Desktop.
Return palindrome of string using recursion
from test import testEqual
def reverse(s):
if len(s) <= 1:
return s
else:
return s[-1] + reverse(s[:-1])
testEqual(reverse("hello"),"olleh")
testEqual(reverse("l"),"l")
testEqual(reverse("follow"),"wollof")
testEqual(reverse(""),"")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment