Sorting Dictionary of Strings and Numbers

前端 未结 3 1748
感情败类
感情败类 2021-01-24 18:01

I have a dictionary object that needs to be sorted, but the keys are date values in the form

[\'Apr. 2013\',\'May 2013\',\'Feb. 2013\',
\'Mar. 2013\',\'Jul. 2013\',\'         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-24 19:03

    I would replace each key with the respective formula:

    newKey = year * monthRank
    

    monthRank would be 1 for January, 2 for February and so on. newKey could then be used to sort every value. Of course this implys that you would have to parse the old keys in order to identify the monthRank and year, but converting the data from an unstructured data format to a sturctured one includes a cost you have to pay.

    Hope I helped!

提交回复
热议问题