Python Forum

Full Version: Index List
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Write a function that returns a new list from the input list with a string xy inserted before the first 0, but only if this 0 is followed by other zeros.
Eg: [3,5,0,0,0,2,5,4,7] then insert string between 5 and 0 [3,5,0,0,2,5,4,6,7] then return the original list.

Can someone please help me with this exercise? Sad
You need to make an effort first.
We will be glad to help when you have a problem, but will not write the code for you.
(Jul-09-2021, 10:52 PM)a04j Wrote: [ -> ]Write a function that returns a new list from the input list with a string xy inserted before the first 0, but only if this 0 is followed by other zeros.
Eg: [3,5,0,0,0,2,5,4,7] then insert string between 5 and 0 [3,5,0,0,2,5,4,6,7] then return the original list.
The instructions are unclear.
a) Is the original list ‘input’ by the user or passed as an argument to the function?
b) What is ‘string xy’ and where does it come from?
c) The example has one zero removed and an integer inserted in apparently the wrong place.
d) Should the function return both the new and original list?