I had 2 list
daydate=['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
percentday=['0%', '17%', '27%', '11%', '7%', '19%', '19%']
i have converted into dictionary by doing
daydic=dict(zip(daydate, percentday))
the output is coming like
{'Monday': '17%', 'Tuesday': '27%', 'Friday': '19%', 'Wednesday': '11%', 'Thursday': '7%', 'Sunday': '0%', 'Saturday': '19%'}
i want to sort this dictionary like the order of elements in daywise like below
{'Sunday': '0%','Monday': '17%', 'Tuesday': '27%', 'Wednesday': '11%', 'Thursday': '7%', , 'Friday': '19%','Saturday': '19%'}
Help me
Dictionaries should not be considered ordered
They are, in fact, insertion ordered in Python 3.6+ (officially 3.7+), but even so you should prefer to use
OrderedDict
for a robust ordered mapping.In addition, you should never have to type days of the week manually, you can import from
calendar.day_name
and rotate viadeque
: