lambdamusic
2/7/2013 - 9:28 PM

Python: recursion in scheme and python

Python: recursion in scheme and python

# scheme:

(define (downup wd)
  (if (= (count wd) 1)
      (se wd)
      (se wd (downup (bl wd)) wd)))

> (downup 'toe)
(TOE TO T TO TOE)

> (downup 'banana)
(BANANA BANAN BANA BAN BA B BA BAN BANA BANAN BANANA)


# now in python

def downup(word):
    if len(word) == 1:
        return [word]
    return [word] + downup(word[1:]) + [word]

print downup("bananas")