I just learned what recursion is and I am trying to find a way to duplicate letters in a word recursively. It's just a way to practice. If there is a better way to do it without recursion, I am open to any feedback. However, I'm primarily trying to find a solution in order to illuminate what recursion is before I go back to looking at coursework and lecture slides. It won't print the final letter twice.
My code:
def makeDups(young):
if len(young) <= 1:
return young
elif young[0] != young[1]:
return 2 * (young[0]) + makeDups(young[1:])
else:
return makeDups(young[1:])
young = 'abcdefg'
print(young)
print(makeDups(young))