Question: Modifying Lists For this question, in chop.py you will create two similar functions that actually work very differently. Both of these functions will be used
Modifying Lists
For this question, in chop.py you will create two similar functions that actually work very differently. Both of these functions will be used to remove the last item from a list, but will operate in different ways.
Write a function chop that returns its argument with the last item removed. It should not change the argument, but should return a copy without the last item.
testlist
choptestlist # note: returns modified copy
printtestlist # note: original unchanged
Write a function chop that removes the last item from a list given as its argument. The existing list should be changed inplace; the function should not return anything.
testlist
choptestlist # note: no return value
printtestlist
The difference between these two functions is important. The first operates like all of the other functions we've written: taken arguments and returned whatever results it created. The second is possible because lists are mutable: the function takes the reference to the list and changes it inplace.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
