vendredi 10 janvier 2020

Can anyone, please, explain why the code below runs in PyCharm but not in Jupyter Notebook

This is a code meant to generate a random key from a dictionary, test_dict. I ran this code in a Jupyter Notebook file but it didn't work, and returned the error: ''TypeError: 'list' object is not callable''.

When I used PyCharm, it printed the result. I am curious because I tend to run short, test scripts in Jupyter first.

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)

Thank you for your response(s).




Aucun commentaire:

Enregistrer un commentaire