Question: Write a function that takes as input a list that contains nested lists of two (2) elements each. For each nested list (call them pairs),

Write a function that takes as input a list that contains nested lists of two (2) elements each. For each nested list (call them pairs), swap the value of the pairs. This function should be a mutating function that modifies the original list passed in. Specification:

Name: flip_lists

Parameters: a list

Returns: the mutated list (yes, this function both mutates the list _and_ returns the mutated list)

Side Effects this function mutates the list passed in and swaps the values of each pair (nested list) within the list passed in

Example: Given an input: [['hello', 'world'], [1, 2]], the side effect of this function will mutate the original list passed in, resulting in its value being [['world', 'hello'], [2, 1]]

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!