問題:
I have a dict like this:我有一個這樣的字典:
sample = {'ObjectInterpolator': 1629, 'PointInterpolator': 1675, 'RectangleInterpolator': 2042}
I can't figure out how to dump the dict to a JSON file as showed below:我不知道如何將 dict 轉儲到 JSON 文件,如下所示:
{
"name": "interpolator",
"children": [
{"name": "ObjectInterpolator", "size": 1629},
{"name": "PointInterpolator", "size": 1675},
{"name": "RectangleInterpolator", "size": 2042}
]
}
Is there a pythonic way to do this?有沒有一種pythonic的方法來做到這一點?
You may guess that I want to generate a d3
treemap.你可能猜到我想生成一個d3
樹狀圖。
解決方案:
參考一: https://en.stackoom.com/question/19Vsy參考二: https://stackoom.com/question/19Vsy