Write a function repeat_first(data, double down) that takes a list and a bool and returns a new list containing all the

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
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

Post by answerhappygod »

Write A Function Repeat First Data Double Down That Takes A List And A Bool And Returns A New List Containing All The 1
Write A Function Repeat First Data Double Down That Takes A List And A Bool And Returns A New List Containing All The 1 (33.94 KiB) Viewed 43 times
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!
Post Reply