不同之处在于第二种方法不起作用:

>>> {}.update(1, 2)
Traceback (most recent call last):
File "", line 1, in 
TypeError: update expected at most 1 arguments, got 2
dict.update()期望找到一个可重复的键值对,关键字参数或另一个字典:
Update the dictionary with the key/value pairs from other, overwriting existing keys. Return None.
update() accepts either another dictionary object or an iterable of key/value pairs (as tuples or other iterables of length two). If keyword arguments are specified, the dictionary is then updated with those key/value pairs: d.update(red=1, blue=2).

map()是一种通过将第二个参数(和后续参数)的元素应用于第一个参数(必须是可调用的)来生成序列的内置方法。除非您的键对象是可调用的,并且值对象是序列,否则您的第一个方法也将失败。

工作地图()应用程序演示:

>>> def key(v):
... return (v, v)
...
>>> value = range(3)
>>> map(key, value)
[(0, 0), (1, 1), (2, 2)]
>>> product = {}
>>> product.update(map(key, value))
>>> product
{0: 0, 1: 1, 2: 2}

这里map()只是生成键值对,它满足dict.update()期望值。