我有这种类型的列表,我正试图将其转换为字典,但键在重复,我无法这样做
清单如下:
my_list = [['full name ',
' Arthur Schopenhauer',
'date of birth ',
' Friday, February 22, 1788 (232 years ago)',
'place of birth ',
' Gdansk, Pomorskie, Poland',
'date of death ',
' Friday, September 21, 1860 (age: 72 years) ',
'place of death ',
' Frankfurt, Hesse, Germany'],
['full name ',
' Aristotle',
'date of birth ',
' 384 BC (2403 years ago)',
'place of birth ',
' Halkidiki, Macedonia Central, Greece',
'date of death ',
' 322 BC (age: 62 years) ',
'place of death ',
' Evvoia, Greece Central, Greece']]
我想得到的是:
my_dict = {"full name": ['Arthur Schopenhauer', 'Aristotle'],
"date of birth": [' Friday, February 22, 1788 (232 years ago)', '384 BC (2403 years ago)'],
"place of birth": [...],
"date of death": [...],
"place of death": [...]}
你能帮我一些建议或意见吗
您可以使用列表类型为值的
defaultdict
,然后按对(键、值)读取每个列表,并将value
添加到由key
给出的list
中给予
相关问题 更多 >
编程相关推荐