Question
Complete the combine_two_lists() function that takes two integer lists as parameters: num_list1 and num_list2. If these two lists have different lengths, the function returns a
Complete the combine_two_lists() function that takes two integer lists as parameters: num_list1 and num_list2.
If these two lists have different lengths, the function returns a new list made by concatenating num_list1 with num_list2.
If these two lists have the same length, the function returns a new list with the same number of elements. The first element of the new list is the product of the last element of num_list1 with the first element of num_list2. The second element of the new list is the product of the second last element of num_list1 with the second element of num_list2, and so on. Therefore if:
num_list1 = [a, b, c, d]
and
num_list2 = [e, f, g, h]
the the new list would have the elements:
[de, cf, bg, ah]
Some examples of the function being used are shown below.
For example:
Test | Result |
---|---|
num_list1 = [1,2,3,4] num_list2 = [5,6,7,8] new_list = combine_two_lists(num_list1, num_list2) print(new_list) | [20, 18, 14, 8] |
num_list1 = [1,2,3] num_list2 = [4,5,6,7] new_list = combine_two_lists(num_list1, num_list2) print(new_list) | [1, 2, 3, 4, 5, 6, 7] |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started