Python 如何从一个列表创建字典,使第一个项目映射到第二个,第三个映射到第四个,依此类推

Python 如何从一个列表创建字典,使第一个项目映射到第二个,第三个映射到第四个,依此类推,python,list,dictionary,Python,List,Dictionary,我有一个字符串和整数列表: students = ['Janet', 21, 'Bill', 19, 'Amanda', 22, 'Mike', 25, 'Susan', 24, 'Jen', 29, 'Sara', 30, 'Maria', 18, 'Kathy', 20, 'Andrew', 27] 我需要制作一个名为peoples的字典,它将每个名字都映射到他们的年龄,年龄是后面的整数。我原以为我必须反复浏览这个列表,但我运气不好。以下是我到目前为止的情况: students = ['J

我有一个字符串和整数列表:

students = ['Janet', 21, 'Bill', 19, 'Amanda', 22, 'Mike', 25, 'Susan', 24, 'Jen', 29, 'Sara', 30, 'Maria', 18, 'Kathy', 20, 'Andrew', 27]
我需要制作一个名为peoples的字典,它将每个名字都映射到他们的年龄,年龄是后面的整数。我原以为我必须反复浏览这个列表,但我运气不好。以下是我到目前为止的情况:

students = ['Janet', 21, 'Bill', 19, 'Amanda', 22, 'Mike', 25, 'Susan', 24, 'Jen', 29, 'Sara', 30, 'Maria', 18, 'Kathy', 20, 'Andrew', 27]
people = {}
for i in students:
    if type(i) is int == False:
        #here I would take i and make it a key in the dictionary, then map the following integer to its value
口述[x代表x,邮编*[Iterstudens]*2] 口述[x代表x,邮编*[Iterstudens]*2] 印刷品:

{'Janet': 21, 'Bill': 19, 'Amanda': 22, 'Mike': 25, 'Susan': 24, 'Jen': 29, 'Sara': 30, 'Maria': 18, 'Kathy': 20, 'Andrew': 27}
印刷品:

{'Janet': 21, 'Bill': 19, 'Amanda': 22, 'Mike': 25, 'Susan': 24, 'Jen': 29, 'Sara': 30, 'Maria': 18, 'Kathy': 20, 'Andrew': 27}

你比我快了20秒!你比我快了20秒!
{'Janet': 21, 'Bill': 19, 'Amanda': 22, 'Mike': 25, 'Susan': 24, 'Jen': 29, 'Sara': 30, 'Maria': 18, 'Kathy': 20, 'Andrew': 27}