Write a function repeat_first(data, double down) that takes a list and a bool and returns a new list containing all the
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Write a function repeat_first(data, double down) that takes a list and a bool and returns a new list containing all the
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, ... %)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!