Question: Write a function called split_pairs that takes a list of integers as a parameter and that returns a new list containing the result of

Write a function called split_pairs that takes a list of integers as

Write a function called split_pairs that takes a list of integers as a parameter and that returns a new list containing the result of splitting successive pairs of numbers so that the first values from each pair appear first followed by the second values from each pair. For example, suppose that a variable called list stores the following: [3, 8, 4, 9, 7, 2] This list has three pairs: (3, 8), (4, 9), and (7, 2). Thus, the call split_pairs (list) should return the following list: [3, 4, 7, 8, 9, 21 Notice that this list contains the first values from each pair (3, 4, 7) followed by the second values from each pair (8, 9, 2). If there is an extra value that is not part of a pair, then it should be included with the first set of values in the new list. For example, if list stores: [7, 5, 3, 2, 8, 4, 6] then the call split_pairs (list) should return: [7, 3, 8, 6, 5, 2, 41 The value 6 in the original list is not part of a pair. Notice that the new list has the first values from each pair (7, 3, 8) followed by 6 followed by the second values from each pair (5, 2, 4). The function should not construct any extra data structures other than the list to be returned andit should not alter its parameter.

Step by Step Solution

3.47 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The detailed ... View full answer

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 Programming Questions!