0

I see option converting date Jan 22 2016 to day Monday as a integer 0 using weekday().
But can I convert day as input to integer.
e.g. Friday to 4 .
Input is not a date, it's just a day e.g. Friday

user2661518
  • 2,677
  • 9
  • 42
  • 79

2 Answers2

3

IIUC, you need

>>> import calendar
>>> list(calendar.day_name)
['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

Having this list you can easily find index or build dict from it

Slam
  • 8,112
  • 1
  • 36
  • 44
3

There is a friendly calendar module

import calendar
dict(zip(calendar.day_name,range(7)))['Monday'] #0
mad_
  • 8,121
  • 2
  • 25
  • 40