假设你有如下两个list:
keys = ['name', 'age', 'food']
values = ['Monty', 42, 'spam']
如何转变成:
a_dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'}
>>> keys = ['a', 'b', 'c'] >>> values = [1, 2, 3] >>> dictionary = dict(zip(keys, values)) >>> print(dictionary) {'a': 1, 'b': 2, 'c': 3}