Answers for "Write a recursive function to reverse a list"

0

Write a recursive function to reverse a list

l = [1,2,4,6]
def recursive(l):
    if len(l) == 0:
        return []  # base case
    else:
        return [l.pop()] + recursive(l)  # recusrive case


print recursive(l)

>[6,4,2,1]
Posted by: Guest on January-29-2021

Code answers related to "Write a recursive function to reverse a list"

Browse Popular Code Answers by Language