I am trying to reverse a list in python 2. The following Code 1 works. But the code 2 comes up with a Nonetype attribution error. What is wrong with using the .append method?
Code1
def list_reverse_right(my_list):
if len(my_list) <= 1:
return my_list
else:
return list_reverse_right(my_list[1:]) + my_list[:1]
print list_reverse_right([2, 3, 1])
Code 2
def list_reverse_wrong(my_list):
if len(my_list) <= 1:
return my_list
else:
return list_reverse_wrong(my_list[1:]).append(my_list[0])
print list_reverse_wrong([2, 3, 1])