Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Index List
#1
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
Reply
#2
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.
Reply
#3
(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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to fix list index out of range longmen 26 5,692 Apr-27-2022, 05:46 PM
Last Post: deanhystad
  list index out of range OliverG 3 2,288 Sep-03-2021, 12:04 AM
Last Post: itsmycode
  List index out of range when turning CSV into dict ranbarr 15 6,277 May-12-2021, 10:38 AM
Last Post: ranbarr
  List vs index: Frederico_Caldas 5 3,524 Jul-03-2020, 10:55 AM
Last Post: DeaD_EyE
  To find the index of the first occurrence of the key in the provided list Angry_bird89 4 3,192 Jun-20-2020, 06:53 PM
Last Post: Angry_bird89
  list index out of range mcgrim 2 2,858 May-25-2019, 07:44 PM
Last Post: mcgrim
  IndexError: list index out of range abdullahali 4 3,793 Jan-17-2019, 07:54 AM
Last Post: buran
  "List index out of range" for output values pegn305 3 5,252 Nov-26-2017, 02:20 PM
Last Post: heiner55
  list index out of range DrPengin 1 3,658 Nov-09-2017, 08:35 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020