Task 1: Program Analysis Write a function cutEdges that removes the first and the last two items from a list given as its argument. The existing list should be changed in-place; the function should not return anything..programmed in python
The function cutEdges is:
def cutEdges(arr):
arr.pop(0) # removing the first item of the list
arr.pop() # removing the last two items of the list
arr.pop()
The sample of the program is:
def cutEdges(arr):
arr.pop(0) # removing the first item of the list
arr.pop() # removing the last two items of the list
arr.pop()
arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # a sample of the list is taken
cutEdges(arr)
print(*arr)
The sample screenshot of preogram and output is:
If a mutable object is passed into a function, the function gets a reference to that same object and we can modify it as we want, but if we assign new values to the reference, the outer scope will know nothing about it and it will still point at the original object.
Get Answers For Free
Most questions answered within 1 hours.