I have a python dictionary with the following format.
{'range_qty':
{'0 to 10 qty': 5,
'more than 5000 qty': 18,
'500 to 1000 qty': 20,
'200 to 500 qty': 19,
'1000 to 5000 qty': 15,
'10 to 50 qty': 3,
'50 to 200 qty': 14}}
How can I sort this dictionary by the key ? I need output like
{'range_qty':
{'0 to 10 qty': 5,
'10 to 50 qty': 3,
'50 to 200 qty': 14,
'200 to 500 qty': 19,
'500 to 1000 qty': 20,
'1000 to 5000 qty': 15,
'more than 5000 qty': 18,
}}
0,10,50and so on, and measure the gap from the last key to the current key to determinate the quantity in between.50 to 200 qtyhas a value of14which is no where in between. OP also wants to sort it by the key, not the value, although that change in the linked answer is minuscule.