我有一個數據結構(從YAML文檔創建),看起來像這樣:如何在Python中對此數據結構進行排序?
{
'SD_TX_EN_CFG[5]': {'Bits': {0: 'ENTX // 0 = Disabled, 1 = Enabled'}, 'Name': 'TX Enable Register (Link 5)', 'Offset': 43024},
'SD_TX_EN_CFG[4]': {'Bits': {0: 'ENTX // 0 = Disabled, 1 = Enabled'}, 'Name': 'TX Enable Register (Link 4)', 'Offset': 40976},
'SD_RX_EN_CFG[5]': {'Bits': {0: 'ENRX // 0 = Disabled, 1 = Enabled'}, 'Name': 'RX Enable Register (Link 5)', 'Offset': 43008},
'SD_RX_EN_CFG[3]': {'Bits': {0: 'ENRX // 0 = Disabled, 1 = Enabled'}, 'Name': 'RX Enable Register (Link 3)', 'Offset': 38912},
'SD_RX_EN_CFG[2]': {'Bits': {0: 'ENRX // 0 = Disabled, 1 = Enabled'}, 'Name': 'RX Enable Register (Link 2)', 'Offset': 36864},
'SD_RX_EN_CFG[0]': {'Bits': {0: 'ENRX // 0 = Disabled, 1 = Enabled'}, 'Name': 'RX Enable Register (Link 0)', 'Offset': 32768},
'aif2_scratch': {'Offset': 4, 'Bits': {'0-31': 'scratch'}, 'Description': None, 'Name': 'aif2_scratch'},
'SD_RX_R2_CFG[0]': {'Bits': {'15-16': 'RXLOOPBACK // 00 = Disabled, 11 = Enabled'}, 'Name': 'RX Configuration Register 2 (Link 0)', 'Offset': 32776},
'aif2_pid': {'Offset': 0, 'Bits': {'6-7': 'Custom version code', '8-10': 'Major revision X code // \n Should be 1\n', '0-5': 'Minor revision Y code'}, 'Description': None, 'Name': 'aif2_pid'},
'SD_TX_EN_CFG[1]': {'Bits': {0: 'ENTX // 0 = Disabled, 1 = Enabled'}, 'Name': 'TX Enable Register (Link 1)', 'Offset': 34832},
'SD_TX_EN_CFG[0]': {'Bits': {0: 'ENTX // 0 = Disabled, 1 = Enabled'}, 'Name': 'TX Enable Register (Link 0)', 'Offset': 32784},
'SD_RX_EN_CFG[1]': {'Bits': {0: 'ENRX // 0 = Disabled, 1 = Enabled'}, 'Name': 'RX Enable Register (Link 1)', 'Offset': 34816},
'SD_RX_EN_CFG[4]': {'Bits': {0: 'ENRX // 0 = Disabled, 1 = Enabled'}, 'Name': 'RX Enable Register (Link 4)', 'Offset': 40960},
'SD_TX_R1_CFG[0]': {'Bits': {'15-16': 'TXLOOPBACK // 00 = Disabled, 11 = Enabled'}, 'Name': 'TX Configuration Register 1 (Link 0)', 'Offset': 32788},
'SD_TX_EN_CFG[2]': {'Bits': {0: 'ENTX // 0 = Disabled, 1 = Enabled'}, 'Name': 'TX Enable Register (Link 2)', 'Offset': 36880},
'RM_LK_CFG0[0]': {'Bits': {0: 'Short frame mode // 0 = CPRI, 1 = OBSAI', '2-3': 'Link Rate // 0 = 8x, 1 = 4x, 2 = 2x, 3 = 1x', 1: 'Enable RM Link // 0 = Disabled, 1 = Enabled'}, 'Name': 'RM Link Configuration Register 0 (Link 0)', 'Offset': 327680},
'SD_TX_EN_CFG[3]': {'Bits': {0: 'ENTX // 0 = Disabled, 1 = Enabled'}, 'Name': 'TX Enable Register (Link 3)', 'Offset': 38928}
}
的YAML定義看起來像
SD_RX_EN_CFG[0]:
Name: RX Enable Register (Link 0)
Offset: 0x8000
Bits:
0: ENRX // 0 = Disabled, 1 = Enabled
等
我想處理每個元素的順序由'Offset'定義,但我似乎無法做到這一點。我已閱讀並重新閱讀72899問題,但這似乎更復雜一些。
對於懶:問題72899](http://stackoverflow.com/q/ 72899/566644) – 2012-02-16 13:30:21