使用字典理解:
{key: value for (key, value) in iterable}注意:这适用于Python 3.x(及2.7及更高版本)。以前在Python 2.6和更早版本中,dict内置函数可以接收可迭代的键/值对,因此您可以将其传递给列表理解或生成器表达式。例如:
dict((key, func(key)) for key in keys)
在简单的情况下,您根本不需要理解…
但是,如果您已经具有可迭代的键和/或值,只需dict直接调用内置函数即可:
1) consumed from any iterable yielding pairs of keys/valsdict(pairs)2) "zip'ped" from two separate iterables of keys/valsdict(zip(list_of_keys, list_of_values))



