suyash gautam
suyash gautam

Reputation: 169

Convert Days of week into corresponding number using lists

I have to write a function day_to_number(day) that takes the supplied global list day_list and returns the position of the given day in that list. I can't seem to make it work.

Here is my code.

day_list = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

def day_to_number(day):
    for day in day_list:
        return day_list.index(day)

print day_to_number("Saturday") 

Thanks for the help in advance

Upvotes: 0

Views: 472

Answers (1)

Dmitry Yudin
Dmitry Yudin

Reputation: 978

>>> day_list.index("Sunday")
0

Just use index of

Upvotes: 1

Related Questions