第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在python中向json添加節(jié)點(diǎn)

在python中向json添加節(jié)點(diǎn)

肥皂起泡泡 2021-09-11 19:35:36
我正在嘗試使用以下代碼在 python 中生成自定義 JSONroot={}Levels=[['L1','L1','L2'],        ['L1','L1','L3'],        ['L1','L2'],        ['L2','L2','L3'],        ['L2','L2','L1'],        ['L3','L2'],        ['L4','L2','L1'],        ['L4','L2','L4']]def append_path(root, paths):    if paths:        child = root.setdefault(paths[0], {})        append_path(child, paths[1:])for p in Levels:    append_path(root, p)def convert(d):    templist=[]    noofchildren=0    if(len(d.items())==0):        return ([{}],1)    for k,v in d.items():        temp,children=convert(v)        noofchildren+=children        if(temp):            templist.append({"name":k+"("+str(children)+")",'children':temp})        else:            templist.append({'name': k+"("+str(children)+")", 'children':[{}]})    return (templist,noofchildren)    # Print resultsimport jsonprint(json.dumps(convert(root)[0],  indent=2))我的數(shù)據(jù)集發(fā)生了一些變化 Levels=[[['L1','L1','L2'],[10,20,30]],        [[['L1','L1','L3'],[10,15,20]],        [[['L1','L2'],[20,10]],        [[['L2','L2','L3'],[20,20,30]],        [[['L2','L2','L1'],[10,20,30]]        [[['L3','L2'],[10,20]]        [[['L4','L2','L1'],[10,20,10]]        [[['L4','L2','L4'],[20,40,50]]]如何更改我的代碼以添加此信息?
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 468 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)