Question: Problem 8 In class, we discussed the difference between a pure (or effect-free) function (i.e. one that returns a value, but does not produce an

 Problem 8 In class, we discussed the difference between a pure

Problem 8 In class, we discussed the difference between a pure (or effect-free) function (i.e. one that returns a value, but does not produce an effect) and a mutating function i.e one that changes the value of its parameters). In this exercise, we ask you to demonstrate your understanding o this distinction by implementing the same functionality as both a pure function, and as a mutating function. Both functions take a list of int as a parameter. The pure variant will return a new list containing the integers in reversed order. The mutating variant will retur None, and will instead modify the list that it's given Your functions should have these signatures: def reverse pure (xs) signature: list(int)> list(int) Returns a list of integers in reverse order pass def reverse ut (x) signature: list(int) > NoneType Reverses the list of integers in place pass When implementing reverse nut, consider carefully how one can reverse the items in a list without creating a new list A contrasting example: >> mylist [5, 12, 34, 0. 11 # The list of numbers >>> newlist - reverse-pure (aylist) # Call the pure function >> print(nevlist) 1, 0, 34, 12, 5] >> print (ylist) [5, 12, 34, 0, 11 >> reverse aut (nylist) >> print (ylist) 1, 0, 34, 12, 5] # The new , revers ed list # The original list is unchanged # Call the mutating function (returns None) # Original list is reversed in-place For this problem, you may not use the built-in Python functions for reversing list, reverse and reversed. You should implement the function using a loop

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!