List not recognized as a list?

Hi there. My task is to define a function to swap the first and last items in a list. For my function, I reassign the list with the first item popped and then appended to the end. Then, I reassign again with the now second-to-last item popped and inserted at the beginning. Everything works well until the .insert. It seems that on this line, user_list is no longer recognized as a list. I’m getting AttributeError: ‘NoneType’ object has no attribute ‘insert’. Also, at this point in the code, PyCharm doesn’t offer any built-in list-type functions. How can my list cease to be a list?

def swap(user_list):
    user_list = user_list.append(user_list.pop(0))
    user_list = user_list.insert(0, user_list.pop(-2))
    return user_list

values_list = input().split(',')  # Program receives comma-separated values like 5,4,12,19
swap(values_list)

print(values_list)

Thanks for any suggestions!

The list append() method doesn’t return anything . You can also say that the append() method returns None .

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.