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,485
  • 7
  • 34
  • 71

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
  • 7,677
  • 1
  • 33
  • 43
3

There is a friendly calendar module

import calendar
dict(zip(calendar.day_name,range(7)))['Monday'] #0
mad_
  • 7,844
  • 2
  • 22
  • 37