Reference no: EM132355604
Question:
Write list functions that carry out the following tasks for a list of integers. Use the main function as test program.
• Write a function named swap that swaps the first and last elements in the list.
• Write a function named shift that shifts all elements by one to the right and move the last element Into the first position. For example, (1, 2, 3, 4, 5) would be transformed into (2, 3, 4, 5, 1).
• Write a function named shift k that shifts all elements k to the right and move the last k elements Into the first k positions. For example, if the original list Is (1, 2, 3, 4, 51, after calling shif t_k (list, 3) the list becomes (4, 5, 1, 2, 3).
• Write a function named shuffle that given a list returns a random shuffled of the list. For example, if the original list is [1, 2, 3, 4, 5], after calling shuffle (list) , the list can be shuffled as (5, 2, 1, 3, 4). Do NOT use shuffle function of random package.
• Write a function named killEvens that replace all the even elements with 0.
• Write a function named mySort that sorts all the elements in the list in ascending order. Do NOT use sort method of lists.