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:
Your result
variable is a string
and not a list
object. Also, it only gets updated one time which is when it is equal to the passed weekday
argument.
Here's an implementation:
import calendar
def weekdays(weekday):
days = [day for day in calendar.day_name]
for day in days:
days.insert(0, days.pop()) # add last day as new first day of list
if days[0] == weekday: # if new first day same as weekday then all done
break
return days
Example output:
>>> weekdays("Wednesday")
['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday']
>>> weekdays("Friday")
['Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday']
>>> weekdays("Tuesday")
['Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday']