Question: I'm to rewrite the swap code so it works properly 2. Consider the following function intended to swap the items in positions i,j of mytist.
2. Consider the following function intended to swap the items in positions i,j of mytist. def swap (1, 5 , mylist) : temp = mylist [i] mytist. insert (i, myList (j]) myList. insert ( j, temp) If myList is ["a", "b", "c", "d", "e", "f"], then swap (1, 4, myList) should change myList into ["a","e","c","d","b","f"]. The function doesn't work as intended. (a) (2 pts) Trace the code for swap (1, 4, ["a", "b", "c", "d", "e", "f"]) by showing the contents of myList after each line. (b) (4 pts) Rewrite the swap method so that is behaves correctly. Your function must modify the list myis given as an argument rather than creating a new list
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
