今天,我遇到了这个dict
方法get
,它给出了字典中的一个键,返回了相关的值.
这个功能用于什么目的?如果我想找到与字典中的键相关联的值,我可以这样做dict[key]
,它返回相同的东西:
dictionary = {"Name": "Harry", "Age": 17}
dictionary["Name"]
dictionary.get("Name")
Run Code Online (Sandbox Code Playgroud) 这让我有点悲伤......
我从列表中创建了一个字典
l = ['a','b','c']
d = dict.fromkeys(l, [0,0]) # initializing dictionary with [0,0] as values
d['a'] is d['b'] # returns True
Run Code Online (Sandbox Code Playgroud)
如何使字典的每个值成为单独的列表?这是否可能不迭代所有键并将它们设置为等于列表?我想修改一个列表而不更改所有其他列表.