标签:end int print 数据处理 turn form lse _for 电脑
industry_list = [
{
"parent_ind" : "女装",
"name" : "连衣裙"
},
{
"name": "女装"
},
{
"parent_ind" : "女装",
"name" : "半身裙"
},
{
"parent_ind" : "女装",
"name" : "A字裙"
},
{
"name": "数码"
},
{
"parent_ind" : "数码",
"name": "电脑配件"
},
{
"parent_ind" : "电脑配件",
"name": "内存"
},
]
lst1 = []
lst2 = []
d = {}
def convert_format(data):
for dic in data:
if not dic.get("parent_ind"):
d[dic["name"]] = {}
else:
lst1.append(dic)
for dic in lst1:
if dic[‘parent_ind‘] in d:
d[dic.get(‘parent_ind‘)][dic[‘name‘]] = {}
else:
lst2.append(dic)
for dic in lst2:
for t in d.values():
if dic[‘parent_ind‘] in t:
t[dic[‘parent_ind‘]][dic[‘name‘]] = {}
return d
print(convert_format(industry_list))
标签:end int print 数据处理 turn form lse _for 电脑
原文地址:https://www.cnblogs.com/mqhpy/p/12743635.html