小编Art*_*nov的帖子

?将列表值转换为字典作为键和值

假设有一个列表:['1604780184', '10', '1604780194', '0', '1604780319', '99', '1604780320', '0']

您需要得到如下结果:{'1604780184': '10', '1604780194': '0', '1604780319': '99', '1604780320': '0'}

现在我有这样的:

rline = ['1604780184', '10', '1604780194', '0', '1604780319', '99', '1604780320', '0']
total = {}
print(f"My list: {rline}")

while rline:
    total[rline[0:2][0]] = rline[0:2][1]
    del rline[0:2]

print(f"Dictionary: {total}")
Run Code Online (Sandbox Code Playgroud)

请告知更好的方法。谢谢。

python dictionary list

2
推荐指数
1
解决办法
62
查看次数

标签 统计

dictionary ×1

list ×1

python ×1