小编Roh*_*yal的帖子

Python dict歧义

我想使用Python关键字dict返回一个字典,其中每个单词都是给定句子的真值。该代码段是:

return dict((word, True) for word in words)
Run Code Online (Sandbox Code Playgroud)

现在,当两个代码返回相同的字典时就会出现歧义:

1。

return dict((word, True) for word in words)
Run Code Online (Sandbox Code Playgroud)

2。

return dict([(word, True) for word in words])
Run Code Online (Sandbox Code Playgroud)

为什么第二个代码段不返回包含单词列表的字典?

python dictionary loops list python-3.x

-2
推荐指数
1
解决办法
141
查看次数

标签 统计

dictionary ×1

list ×1

loops ×1

python ×1

python-3.x ×1