Return to Snippet

Revision: 43207
at March 19, 2011 01:56 by magicrebirth


Initial Code
# 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")

Initial URL
http://stackoverflow.com/questions/5300242/scheme-to-python-most-elegant-translation-of-a-recursive-procedure

Initial Description

                                

Initial Title
recursion in scheme and python

Initial Tags
python

Initial Language
Python