Return a list of weekdays, starting with given weekday

后端 未结 9 2358
情书的邮戳
情书的邮戳 2021-02-07 23:53

My task is to define a function weekdays(weekday) that returns a list of weekdays, starting with the given weekday. It should work like this:

9条回答
  •  走了就别回头了
    2021-02-08 00:24

    You don't need to hardcode array of weekdays. It's already available in calendar module.

    import calendar as cal
    
    def weekdays(weekday):
        start = [d for d in cal.day_name].index(weekday)
        return [cal.day_name[(i+start) % 7] for i in range(7)]
    

提交回复
热议问题