Python datetime weekday number code - dynamically? -
to weekday no, import datetime print datetime.datetime.today().weekday() the output integer within range of 0 - 6 indicating monday 0 @ doc-weekday i know how values python i wish create dictionary dynamically such as, {'monday':0, 'tuesday':1,...} the following code create dict d required values >>> import calendar >>> d=dict(enumerate(calendar.day_name)) >>> d {0: 'monday', 1: 'tuesday', 2: 'wednesday', 3: 'thursday', 4: 'friday', 5: 'saturday', 6: 'sunday'} edit: comment below @mfripp gives better method >>> d=dict(zip(calendar.day_name,range(7))) >>> d {'monday': 0, 'tuesday': 1, 'friday': 4, 'wednesday': 2, 'thursday': 3, 'sunday': 6, 'saturday': 5}