Exercise: Reverse String With Recursion

Run Settings
LanguagePython
Language Version
Run Command
#Implement a function that reverses a string using iteration...and then recursion! def reverseStringIterative(word): word = list(word) i, j = 0, len(word)-1 while i < j: word[i], word[j] = word[j], word[i] i += 1 j -= 1 return ''.join(word) def reverseStringRecursive(word): if len(word) == 1: return word return reverseStringRecursive(word[1:]) + word[0] result = reverseStringIterative('yoyo mastery') print(result) result = reverseStringRecursive('yoyo mastery') print(result) #should return: 'yretsam oyoy'
Editor Settings
Theme
Key bindings
Full width
Lines