小编End*_*ide的帖子

将列表添加到字典时出现“ TypeError:'NoneType'对象不可调用”

我正在创建一个将几个列表合并为一个字符串的函数,并且遇到以下错误。

Traceback (most recent call last):
  File "TraditionalRoute\BioKeywords.py", line 65, in <module>
    print(PrintKeyDefs())
  File "TraditionalRoute\BioKeywords.py", line 30, in PrintKeyDefs
    defsTwo = dict(map(None, letters, defsOne))
TypeError: 'NoneType' object is not callable
Run Code Online (Sandbox Code Playgroud)

我的代码如下:

# print keyword and three definitions, one of which is the correct definition
def PrintKeyDefs():
   print('\nRandomly selected keyword:',SelectKeyword(),'\n')
   # definitions below
   defsOne = []
   defsOne.append(keywords[ChosenKeyword]) # choosing the keyword
   RandDefCount = 0
   while RandDefCount < 2: # adding two random keywords to the list
      defsOne.append(keywords[random.choice(words)])
      RandDefCount += 1
   random.shuffle(defsOne) …
Run Code Online (Sandbox Code Playgroud)

python dictionary

1
推荐指数
1
解决办法
3100
查看次数

标签 统计

dictionary ×1

python ×1