我有這樣的dict_sample
結構:
{'close': {'01/01/2022': 70327.6216, '02/01/2022': 69699.74376000001, '03/01/2022': 68400.97064, '04/01/2022': 67238.73537000001, '05/01/2022': 63901.21185000001, '06/01/2022': 63857.56575, '07/01/2022': 61243.99047, '08/01/2022': 61428.6952},
'high': {'01/01/2022': 70592.20832, '02/01/2022': 70632.42668, '03/01/2022': 70059.4992, '04/01/2022': 69685.67126, '05/01/2022': 69189.04710000001, '06/01/2022': 64857.41691000001, '07/01/2022': 63574.54257, '08/01/2022': 62360.916040000004},
'low': {'01/01/2022': 68087.621, '02/01/2022': 68825.25224, '03/01/2022': 67331.1328, '04/01/2022': 66893.72049, '05/01/2022': 62590.39965, '06/01/2022': 62944.24587, '07/01/2022': 60158.021, '08/01/2022': 59810.57563},
'open': {'01/01/2022': 68087.621, '02/01/2022': 70328.65284, '03/01/2022': 69673.37348000001, '04/01/2022': 68116.52833, '05/01/2022': 67443.40665, '06/01/2022': 64352.60172, '07/01/2022': 63530.61439, '08/01/2022': 61250.77133},
'volume': {'01/01/2022': 31239, '02/01/2022': 27020, '03/01/2022': 41062, '04/01/2022': 55589, '05/01/2022': 83744, '06/01/2022': 63076, '07/01/2022': 88358, '08/01/2022': 52544}}
我需要創建一個new_dict_sample
withdict_sample
包裹在一個名為的串列結構中,比如historical
,這將使它看起來像這樣:
{'historical:
[{'close': {'01/01/2022': 70327.6216, '02/01/2022': 69699.74376000001, '03/01/2022': 68400.97064, '04/01/2022': 67238.73537000001, '05/01/2022': 63901.21185000001, '06/01/2022': 63857.56575, '07/01/2022': 61243.99047, '08/01/2022': 61428.6952},
'high': {'01/01/2022': 70592.20832, '02/01/2022': 70632.42668, '03/01/2022': 70059.4992, '04/01/2022': 69685.67126, '05/01/2022': 69189.04710000001, '06/01/2022': 64857.41691000001, '07/01/2022': 63574.54257, '08/01/2022': 62360.916040000004},
'low': {'01/01/2022': 68087.621, '02/01/2022': 68825.25224, '03/01/2022': 67331.1328, '04/01/2022': 66893.72049, '05/01/2022': 62590.39965, '06/01/2022': 62944.24587, '07/01/2022': 60158.021, '08/01/2022': 59810.57563},
'open': {'01/01/2022': 68087.621, '02/01/2022': 70328.65284, '03/01/2022': 69673.37348000001, '04/01/2022': 68116.52833, '05/01/2022': 67443.40665, '06/01/2022': 64352.60172, '07/01/2022': 63530.61439, '08/01/2022': 61250.77133},
'volume': {'01/01/2022': 31239, '02/01/2022': 27020, '03/01/2022': 41062, '04/01/2022': 55589, '05/01/2022': 83744, '06/01/2022': 63076, '07/01/2022': 88358, '08/01/2022': 52544}}]}
我嘗試了以下方法,但它回傳錯誤:
new_dict_sample = [{k : val[x] for k, val in dict_sample.items()}
for x in range(2)]
我在這里想念什么?非常感謝任何幫助!
uj5u.com熱心網友回復:
您可以使用:new_dict_sample = { 'historical': [dict_sample]};
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/504900.html
上一篇:如何使字典的亂數值保持不變
下一篇:使用字串作為字典的索引