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

How do I fill in days of the week between two days

I have a list like ['Monday', 'Thursday'] with two days of the week. I want to be able to retrieve a list of days of the week between these two -> ['Monday', 'Tuesday', 'Wednesday', 'Thursday']

  1. I am happy to write a custom function in Python to do this. But wondering if there is an easier way that I might be missing.

  2. How can I retrieve the day index for a given day of the week (day of the week name – example:’Wednesday’) in Python?

    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 :

To retrieve a list of days of the week between two given days, you can use below function:

def days_between(start_day, end_day):
    days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
    start_index = days.index(start_day)
    end_index = days.index(end_day)
        
    if start_index <= end_index:
        return days[start_index:end_index+1]
    else:
        return days[start_index:] + days[:end_index+1]
    
# Example usage
start_day = 'Monday'
end_day = 'Thursday'
result = days_between(start_day, end_day)
print(result)
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