Question: using basic python -) [40 marks] Write a function named alternate that takes two lists and returns a new list containing alternating elements of the
-) [40 marks] Write a function named alternate that takes two lists and returns a new list containing alternating elements of the given lists. For example, a call to alternate([1, 2], ['a', 'b']) should return [1, 'a', 2, 'b']. If the given lists have different lengths, simply append the remaining elements of the longer list to the new list (the result). Please see the examples below. result = alternate([1, 2], ['a', 'b']) print(result) [1, 'a', 2, 'b'] result = alternate([1, 2, 3, 4], ['a', 'b']) print(result) [1, a', 2, 'b', 3, 4] result = alternate([1, 2], ['a', b', ' cd']) print(result) [1, 'a', 2, 'b', 'c','d'] result = alternate([], ['a', 'b', ' cd']) print(result) ['a', 'b', 'c','d'] co
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
