如何初始化一个字典与列表和空值在Python中的钥匙
1个回答
推荐于2018-03-26
展开全部
1. dict.fromkeys([1, 2, 3, 4])这实际上是一个所以它适用于字典-子类(如collections.defaultdict)为好。可选的第二个参数指定的键(默认为值None。)
2.
dict.fromkeys(keys, None)
3.
>>> keys = [1,2,3,5,6,7]
>>> {key: None for key in keys}
{1: None, 2: None, 3: None, 5: None, 6: None, 7: None}
4.
d = {}
for i in list:
d[i] = None
2.
dict.fromkeys(keys, None)
3.
>>> keys = [1,2,3,5,6,7]
>>> {key: None for key in keys}
{1: None, 2: None, 3: None, 5: None, 6: None, 7: None}
4.
d = {}
for i in list:
d[i] = None
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询