I'm having trouble with this question:
Write a function insert_item_end(data, item) that takes a list data, and item as a parameter and returns a new list that contains item at the end of the data using the insert method (i.e. you cannot use append).
This is what I've done so far:
data.insert(-1, item)
However, this only returns None.
Here is an example of what I want to return:
([1, 2, 3, 4, 5], 1) returns [1, 2, 3, 4, 5, 1]
list.insertalways returnsNone. But it modifies thelistobject in-place. Note also, it inserts before the index, sodata.insert(-1, 1)would give you[1,2,3,4,1,5].insert(although, inserting at the end is just.append) to do this, but you would have to copy the incoming list first. Then modify that list, and return it. There is probably a cleaner way to do that than explicitly copying...insertin a way in which it was not designed (i.e. the reason we haveappend) and 2) forces the student to write verbose code, which is neither efficient nor Pythonic. Suggestion: Find a new course. Quick!