Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: Check Next List in Nested List

month = [[0,1,0,1,0,1,1], [1,1,1,1,1,1,1], [0,0,0,0,0,0,1], [1,0,0,0,0,0,1]]

each nested list corresponds to a week and
each 1 corresponds to an "event" and each event has a random length between 2-14
Example:
I want to enter the event at month[0][5] with a length of 6 days
how do I make it so that the next 6 days all the "events" (including the events that cross the current week) turn 0?

Expected Output:

month = [[0,1,0,1,0,1,0], [0,0,0,0,0,1,1], [0,0,0,0,0,0,1], [1,0,0,0,0,0,1]]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

here is one way :

week, day = 0, 5 #starting point eg: month[0][5]
event_days = 6
for _ in range(event_days):
    week, day = (week + 1, 0) if day == len(month[week])-1 else (week, day + 1)
    month[week][day] = 0

output:

>>
[
  [0, 1, 0, 1, 0, 1, 0]
, [0, 0, 0, 0, 0, 1, 1]
, [0, 0, 0, 0, 0, 0, 1]
, [1, 0, 0, 0, 0, 0, 1]
]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading