Did I write this recursively?
<p>I need to write a recursive method to reverse a list, using no loops and no built-in functions such as <strong>reverse, reversed</strong>, or <strong>::</strong> (the list-slicing operator).</p>

<p>Did I do this properly?</p>

<pre><code>def reverseList(alist):
    if len(alist) == 1:
        return alist
    else:
        return reverseList(alist[1:]) + [alist[0]]

print (reverseList([1,2,3,4,5]))
</code></pre>

<p>Yes, you did great.  The code is short, clear, readable, and calls itself appropriately.  Yes, you can recode this for the empty list.</p>

<pre><code>if len(alist) &lt;= 1:
    return alist
</code></pre>

<p>Also, try a few more test cases:</p>

<pre><code>print (reverseList([1,2,3,4,5]))
print (reverseList([1, [False, 2.71828], ["hello", "world", "I'm", "done"], 4, 5]))
print (reverseList([])
print (reverseList([7])
</code></pre>

python recursion