Question: NOTE: I can't use map / zip or lambda Define a function named get_sorted_in_parallel(tuples1, tuples2) which takes two tuples of integers as parameters. The tuples

NOTE: I can't use map / zip or lambda

Define a function named get_sorted_in_parallel(tuples1, tuples2) which takes two tuples of integers as parameters. The tuples have the same length and their elements are related, i.e. the element at each index of the second parameter tuple corresponds to the element at the same index in the first parameter tuple, e.g. the element at index 1 in the first tuple corresponds to the element at index 1 in the second tuple. The function sorts the first parameter tuple, keeping the elements of the second parameter tuple in the order corresponding to the sorted first parameter tuple. The function returns a tuple made up of the sorted first parameter tuple and the new corresponding second tuple. For example, the following code fragment:

tuple1 = (4, 1, 3) tuple2 = (9, 8, 6) tuple3, tuple4 = get_sorted_in_parallel(tuple1, tuple2) print(tuple1, "-", tuple2) print(tuple3, "-", tuple4)

prints:

(4, 1, 3) - (9, 8, 6) (1, 3, 4) - (8, 6, 9)

4 and 9 are connected, 1 and 8 are connected, 3 and 6 are connected. The function sorts the first tuple, so 1 is the first element in the first tuple, so 8 will be the first element in the second tuple. 3 is the second element in the first tuple, so 6 will be the second element in the second tuple. 4 is the last element in the first tuple, so 9 will be the last element in the second tuple.

Note: you can assume that the tuple1 parameter contains unique elements (i.e. no duplicates).

For example:

Test Result
tuple1 = (5, 6, 2, 1, 3) tuple2 = (3, 8, 9, 6, 7) tuple3, tuple4 = get_sorted_in_parallel(tuple1, tuple2) print(tuple1, "-", tuple2) print(tuple3, "-", tuple4)
(5, 6, 2, 1, 3) - (3, 8, 9, 6, 7) (1, 2, 3, 5, 6) - (6, 9, 7, 3, 8)
tuple1 = (3, 8, 4, 9, 1, 2, 7) tuple2 = (43, 24, 76, 12, 9, 23, 14) tuple3, tuple4 = get_sorted_in_parallel(tuple1, tuple2) print(tuple1, "-", tuple2) print(tuple3, "-", tuple4)
(3, 8, 4, 9, 1, 2, 7) - (43, 24, 76, 12, 9, 23, 14) (1, 2, 3, 4, 7, 8, 9) - (9, 23, 43, 76, 14, 24, 12) 

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!