Define a function called list_split_and_reverse(a_list) that takes a list as input. If the list is empty, print "List is empty, fail!" and return nothing. If the list has an odd number of elements print "List has odd number of elements, fail!" and return nothing. Otherwise split the list into two entirely new lists, one containing the first half of the elements, and the other containing the other half. Reverse the back-half/second list >>> a_list = [0, 2, 3, 7, 10, 20] >>> result = list_split_and_reverse([]) Output: List is empty, fail! # result is also empty/None >>> result = list_split_and_reverse(a_list[:-1]) Output: List has odd number of elements, fail! # result is also empty/None >>> result = list_split_and_reverse(a_list) >>> print(result) Output: ([0, 2, 3], [20, 10, 7]) >>> result1, result2 = list_split_and_reverse([0, 1, 2, 4]) >>> print(result1) Output: [0, 1] >>> print(result2) Output: [4, 2]
Define a function called list_split_and_reverse(a_list) that takes a list as input. If the list is empty, print "List is empty, fail!" and return nothing. If the list has an odd number of elements print "List has odd number of elements, fail!" and return nothing. Otherwise split the list into two entirely new lists, one containing the first half of the elements, and the other containing the other half. Reverse the back-half/second list
>>> a_list = [0, 2, 3, 7, 10, 20]
>>> result = list_split_and_reverse([])
Output: List is empty, fail! # result is also empty/None
>>> result = list_split_and_reverse(a_list[:-1])
Output: List has odd number of elements, fail! # result is also empty/None
>>> result = list_split_and_reverse(a_list)
>>> print(result)
Output: ([0, 2, 3], [20, 10, 7])
>>> result1, result2 = list_split_and_reverse([0, 1, 2, 4])
>>> print(result1)
Output: [0, 1]
>>> print(result2)
Output: [4, 2]
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images