Write a function repeat_first(data, double down) that takes a list and a bool and returns a new list containing all the
Posted: Wed Apr 27, 2022 3:43 pm
Write a function repeat_first(data, double down) that takes a list and a bool and returns a new list containing all the elements of the input list data but with the first item appearing twice at the beginning of the list. BUT, if double_down is True then the function should instead return a list with all the items in data appearing twice. Your function should not modify the list it is given. (Hint: see the lecture notes on Aliasing if you have trouble with this requirement) For example: Result Test [1, 1, 2, 3, 4, 5, 6] ans = repeat_first([1,2,3,4,5,6). False) print (ans) ans = repeat_first([1, 2, 3), True) [1, 1, 2, 2, 3, 3) print(ans) ans = repeat_first(['hi', 'there', 'what'. 'Tun']. False) ["hi', 'hi', 'there', 'what', 'fun'] print (ans) Answer: (penalty regime: 0, 10, ... %)