Creating a Dictionary from a List of 2-Tuples

孤街醉人 提交于 2019-11-30 20:27:04
Andrey Sboev
>>> l = [('a', 1), ('b', 2)]
>>> d = dict(l)
>>> d['a']
1 

Why not just do this:

d = dict(l)

Also, to answer your question, your solution is failing because y (which is a 2-tuple) has no method update, since it's not a dict. Thankfully, what you're doing is built right in.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!