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.

I'm to rewrite the swap code so it works properly
 I'm to rewrite the swap code so it works properly 2.

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

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!