使用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}
"""

相关文章:

  • 2021-12-21
  • 2019-02-23
  • 2021-07-12
  • 2021-06-14
  • 2022-12-23
  • 2022-02-16
  • 2021-10-01
  • 2021-10-20
猜你喜欢
  • 2022-01-05
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2021-12-17
  • 2021-11-14
相关资源
相似解决方案