gpt4 book ai didi

python - 特定字典的一大列表

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:01 24 4
gpt4 key购买 nike

我正在尝试将列表转换为字典。我尝试了很多解决方案,但找不到完全像这样的方法python dict 是 python 中最好的东西之一,所以我需要 Dict我有一个这样的大 list

[{
'1': {
'1.1': '',
'1.2': '',
'1.3': False
}
}, {
'2': {
'2.1': False
}
}, {
'3': {
'3.1': [100, 91, 100, 100],
'3.2': 5,
'3.3': True,
'3.5': ['Page has no headings', 'This form element has no label.', 'This link has no text inside it.', 'This link text is uninformative.'],
'3.6': 4
}
}, {
'4': {
'4.1': False,
'4.2': False,
'4.3': True
}
}, {
'5': {
'5.1': True,
'5.2': '"2021-12-14 19:00:42"',
'5.3': True
}
}]

我只想要这样的字典

final_result ={
'1': {
'1.1': '',
'1.2': '',
'1.3': False
}
'2': {
'2.1': False
}
'3': {
'3.1': [100, 91, 100, 100],
'3.2': 5,
'3.3': True,
'3.5': ['Page has no headings', 'This form element has no label.', 'This link has no text inside it.', 'This link text is uninformative.'],
'3.6': 4
}
'4': {
'4.1': False,
'4.2': False,
'4.3': True
}
'5': {
'5.1': True,
'5.2': '"2021-12-14 19:00:42"',
'5.3': True
}
}

我尝试了一些方法,但我今天过得很糟糕,所以无法找到解决方案

谢谢

最佳答案

一个简单的循环检索数据更新结果字典就足够了:

l = yourlist
res = {}
for e in l:
res.update(e)

这里有一个live example

关于python - 特定字典的一大列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47091803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com