这是用于从字典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)
感谢您的回复。
您能给我们看一些有关该错误的例子吗?