Last active
September 12, 2016 10:07
-
-
Save samuelbalogh/5084aa26d39f2d1d286f3051cf00a02d to your computer and use it in GitHub Desktop.
Return palindrome of string using recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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