小编I n*_*elp的帖子

列表字典到嵌套字典

我有以下字典{44: [0, 1, 0, 3, 6]},需要将其转换为,dict1 = {44: {0:0, 1:1, 2:0, 3:3, 4:6}}但是我当前的for循环不起作用:

maxnumbers = 5          #this is how many values are within the list
for i in list(range(maxnumbers)):
    for k in list(dict1.keys()):
        for g in dict1[k]:
            newdict[i] = g
print(num4)
Run Code Online (Sandbox Code Playgroud)

你能帮助我吗?提前致谢。

python dictionary list

6
推荐指数
3
解决办法
293
查看次数

标签 统计

dictionary ×1

list ×1

python ×1