mthoutai

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

使用zip函数, 把key和value的list组合在一起, 再转成字典(dict).


代码:

# -*- coding: utf-8 -*-


keys = ['a', 'b', 'c']
values = [1, 2, 3]
dictionary = dict(zip(keys, values))
print dictionary

"""
输出:
{'a': 1, 'c': 3, 'b': 2}
"""

posted on 2017-07-13 08:22  mthoutai  阅读(1469)  评论(0编辑  收藏  举报