You don't need to create a new (ordered) dictionary if you just want to consume (print, write to a file, ...) the data. Just output a list of items (month, count)
.
>>> product_sell= {'November':680,'August':678,'October':857,'January': 125,'April':989,'February': 300, 'September':120,'March':259,'December':899,'June':368, 'May':31,'July':968}
First, you can buld a sort key by month:
>>> import calendar
>>> key_by_month = dict(zip(calendar.month_name[1:], [(-calendar.monthrange(2019,i)[1], i) for i in range(1,13)]))
>>> key_by_month
{'January': (-31, 1), 'February': (-28, 2), 'March': (-31, 3), 'April': (-30, 4), 'May': (-31, 5), 'June': (-30, 6), 'July': (-31, 7), 'August': (-31, 8), 'September': (-30, 9), 'October': (-31, 10), 'November': (-30, 11), 'December': (-31, 12)}
Months will be sorted by number of days (descending, hence the minus sign) and then by their natural order.
Second, use sorted
and find the key by the month name:
>>> sorted(product_sell.items(), key=lambda m_c: key_by_month[m_c[0]])
[('January', 125), ('March', 259), ('May', 31), ('July', 968), ('August', 678), ('October', 857), ('December', 899), ('April', 989), ('June', 368), ('September', 120), ('November', 680), ('February', 300)]
Note: If you can, avoid using month names as keys, because they are subject to variations: "january" vs "January", foreign languages, ...