Q:

Retrieve list of weekdays for any case

Hi everybody I have a small issue of coding:
I have a list of numbers from 0 to 6 that represent days of the week from Sunday to Saturday
So Sunday = 0 and Saturday = 6 
So the list is [0,1,2,3,4,5,6] 
There is no problem to retrieve the list between two days (or number) if the from < to.
example:
from Monday= 1 to Thursday= 4 there are these numbers included : [1,2,3,4]
Problems come when you have to retrieve the list of days when from > to:
example:
from Friday = 5 to Tuesday =2 we need to catch this list : [5, 6, 0, 1, 2]
Do you have idea how can I code an algorithm or a function that will give me a list of days (here numbers)  to include if I give a number "from" and a number "to" whatever "from" is inferior or superior to the "to" value.
Thank you very much for your help.

A:

I would do it this way:
def getweekdays(frm, to):
    days = [0,1,2,3,4,5,6]
    if frm <= to:
        return days[frm:to+1]
    else:
        return days[frm:] + days[:to+1]

(I haven't checked the code, but you get the idea :) )

