Return a list of weekdays, starting with given weekday

后端 未结 9 2332
情书的邮戳
情书的邮戳 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:27

    Here's more what you want:

    def weekdays(weekday):
        days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
        index = days.index(weekday)
        return (days + days)[index:index+7]
    

提交回复
热议问题