谁能解释一下为什么下面的代码在PyCharm中运行而在Jupyter Notebook中却没有运行

问题描述 投票:0回答:1

这是用于从字典test_dict生成随机密钥的代码。我在Jupyter Notebook文件中运行了此代码,但没有成功,并返回了错误:“ TypeError:'list'对象不可调用”。

当我使用PyCharm时,它会打印结果。我很好奇,因为我倾向于先在Jupyter中运行简短的测试脚本。

import random
test_dict = {0: [3], 1: [0], 2: [1, 6], 3: [2], 4: [2], 5: [4], 6: [5, 8], 7: [9], 8: [7], 9: [6]}


result = random.choice(list(test_dict.keys()))

print(result)

感谢您的回复。

python random jupyter-notebook pycharm
1个回答
0
投票

您能给我们看一些有关该错误的例子吗?

© www.soinside.com 2019 - 2024. All rights reserved.