Three More List Manipulation Exercises
October 14, 2016
We have three more list-manipulation exercises today, for those students midway through their beginning programming course who need practice with linked lists:
- Define a function that takes two lists, the second of which is a list of non-negative integers the same length as the first list, and returns a list of elements from the first list, in reverse order, each repeated a number of times as specified by the corresponding element of the second list.
- Rearrange the integers in a list so that all the odd numbers appear before all the even numbers, with both odd and even numbers in the same relative order in the output as they were in the input.
- Write a function that returns the nth item from the end of a list.
Your task is to write the three specified programs. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.