# 练习:将两个列表合并为一个字典 list_student_name = ["悟空", "八戒", "白骨精"] list_student_age = [28, 25, 36] for item in zip(list_student_name,list_student_age): print(dict(item))
时间: 2023-11-27 21:53:31 浏览: 65
可以使用 zip() 函数将两个列表合并成一个元组列表,然后通过 dict() 函数将元组列表转化为字典。代码如下:
```python
list_student_name = ["悟空", "八戒", "白骨精"]
list_student_age = [28, 25, 36]
dictionary = dict(zip(list_student_name, list_student_age))
print(dictionary)
```
输出结果为:
```
{'悟空': 28, '八戒': 25, '白骨精': 36}
```
阅读全文