Python Forum
Index List - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Index List (/thread-34238.html)



Index List - a04j - Jul-09-2021

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


RE: Index List - Larz60+ - Jul-09-2021

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.


RE: Index List - BashBedlam - Jul-10-2021

(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?