Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中的列表到字典_Python_List_Loops_Dictionary - Fatal编程技术网

python中的列表到字典

python中的列表到字典,python,list,loops,dictionary,Python,List,Loops,Dictionary,我有这种类型的列表,我正试图将其转换为字典,但键在重复,我无法这样做 清单如下: 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, Sep

我有这种类型的列表,我正试图将其转换为字典,但键在重复,我无法这样做

清单如下:


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,然后按对键读取每个列表,并将值添加到键给定的列表中

给予

{
    "full name ": [
        " Arthur Schopenhauer",
        " Aristotle"
    ],
    "date of birth ": [
        " Friday, February 22, 1788 (232 years ago)",
        " 384 BC (2403 years ago)"
    ],
    "place of birth ": [
        " Gdansk, Pomorskie, Poland",
        " Halkidiki, Macedonia Central, Greece"
    ],
    "date of death ": [
        " Friday, September 21, 1860 (age: 72 years) ",
        " 322 BC (age: 62 years) "
    ],
    "place of death ": [
        " Frankfurt, Hesse, Germany",
        " Evvoia, Greece Central, Greece"
    ]
}

dictzipmy_list[::2],my_list[1::2]请重新读取,阅读并提供一个。为我实现此功能对于此网站来说是离题的。您必须进行诚实的尝试,然后就您的算法或技术提出一个特定的问题。@inspectorG4dget这是行不通的,因为my_list是一个列表列表。
{
    "full name ": [
        " Arthur Schopenhauer",
        " Aristotle"
    ],
    "date of birth ": [
        " Friday, February 22, 1788 (232 years ago)",
        " 384 BC (2403 years ago)"
    ],
    "place of birth ": [
        " Gdansk, Pomorskie, Poland",
        " Halkidiki, Macedonia Central, Greece"
    ],
    "date of death ": [
        " Friday, September 21, 1860 (age: 72 years) ",
        " 322 BC (age: 62 years) "
    ],
    "place of death ": [
        " Frankfurt, Hesse, Germany",
        " Evvoia, Greece Central, Greece"
    ]
}