日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python 遍历字典嵌套_Python 字典嵌套循环遍历

發(fā)布時(shí)間:2023/12/10 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 遍历字典嵌套_Python 字典嵌套循环遍历 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這是從接口獲取到的json數(shù)據(jù){

* "code":"10000",

* "charge":false,

* "remain":0,

* "msg":"查詢成功",

* "result":{

* "status":0,

* "msg":"ok",

* "result":{

* "total":1384,

* "num":5,

* "list":[

{

* "id":1,

* "classid":2,

* "name":"炸茄盒",

* "peoplenum":"3-4人",

* "preparetime":"10分鐘內(nèi)",

* "cookingtime":"10-20分鐘",

* "content":"炸茄盒外焦里嫩,入口不膩,咬上一口,淡淡的肉香和茄子的清香同時(shí)浮現(xiàn),讓人心動(dòng)不已。",

* "pic":"http://123123~~~~/recipe/upload/20160719/115137_60657.jpg",

* "tag":"健脾開(kāi)胃,兒童,減肥,宴請(qǐng),家常菜,小吃,炸,白領(lǐng),私房菜,聚會(huì)",

* "material":[

1. {

* "mname":"生粉",

* "type":0,

* "amount":"適量"

},

{...}

{...}

]

"process":[

1. {

* "pcontent":"首先我們將豬肉剁成肉泥、姜切成姜米、蔥切蔥花、蒜子切成蒜末、茄子去皮,然后在每一小段中間切一刀,但不要切斷,做成茄盒。",

* "pic":"http://123123/recipe/upload/20160719/162541_29953.jpg"

},

{[...]}

{[...]}

]

}}}}

請(qǐng)問(wèn)如何遍歷出所有字段數(shù)據(jù)了并可以插入數(shù)據(jù)庫(kù)中,我嘗試了三個(gè)for循環(huán)遍歷最后都是material[]、pcontent[]里面都是重復(fù)插入的值for x in data['result']['result']['list']:

caipu_id = x['id']

classid_id = x['classid']

name = x['name']

peoplenum = x['peoplenum'] # 人數(shù)

preparetime = x['preparetime'] # 做菜時(shí)間

content = x['content'] # 簡(jiǎn)介

pic = x['pic'] # 背景圖

tag = x['tag']

for a in x['material']:

mname_null.append(a['mname'])

amount_null.append(a['amount'])

# mname_null.clear() #清空l(shuí)ist

for (q,d) in zip(mname_null,amount_null):

data_null.append(q)

data_null.append(d)

for i in x['process']:

material_null.append(i['pcontent'])

pic_null.append(i['pic'])

for (g, k) in zip(material_null, pic_null):

process_null.append(g)

process_null.append(k)

總結(jié)

以上是生活随笔為你收集整理的python 遍历字典嵌套_Python 字典嵌套循环遍历的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。