What I expected to happen: When I run the code against test lists, it seems to consistently return the correct solution and remove the list item with the index that I’ve specified.
What actually happened:
Function remove_at_idx did not return a value with the expected type. We expected list but got NoneType instead.
list.remove function does not return any value. It make changes in list object inplace. In python if function does not return any value returns explicit None that is NoneType object.
but if you required to return list any way it could be
remove() is an inbuilt list method in Python programming language that removes a given object from the list . It does not return any value. In simple terms is that it removes the object inplace.
Python Lists has many methods, check the documentation
There are many ways to achieve what you want. Since in your function remove_at_idx you are passing the list and the index, the best method I would use is to use the .pop() list method and return the list
Just trying to wrap my head around this one – so basically, the instructions are to take a list and index as the arguments, remove the element at the index and return a new list. The problem with list.remove is that it changes the original list and therefore DOESN’T return a new list – just a NoneType object.
I think the above makes sense, I’m just trying to better understand why the del and .pop() methods DO work with this task as they both modify the original list, as well.
Still trying to get a better understanding of the various list methods – del and .remove() are quite similar but I suppose the benefit here is that del won’t be affected by duplicate list items?
Would you say that .pop() is superior to del because the method itself is specifically designed to refer to an index and remove it? I suppose both methods ultimately accomplish the same thing, just curious