Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The first time I run this block of code from Notebook it works fine:

#Which letters and how many
letters = ["a","b","c"]
noOfLetters = len(letters)

#Looking for all permutations
resultA = []
from itertools import permutations
for i in range(noOfLetters):
    resultA.append(list(permutations(letters,i+1)))

If I run it again (without restarting the Kernel) I get the following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-5-4050a4ce7a36> in <module>()
      7 from itertools import permutations
      8 for i in range(noOfLetters):
----> 9     resultA.append(list(permutations(letters,i+1)))

TypeError: 'list' object is not callable
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
633 views
Welcome To Ask or Share your Answers For Others

1 Answer

Assuming "notebook" is Jupyter (previously ipython notebooks), you must be careful that jupyter keeps the state of all variables.

--> that means that the second run starts with variables already initialized at the value they had at the end of the first run.

One way to avoid that is to restart the kernel; another is to delete all variables; one more is to initialize all your variables each time you run.

from the docs:

To restart the kernel (i.e. the computational engine), click on the menu Kernel -> Restart. This can be useful to start over a computation from scratch (e.g. variables are deleted, open files are closed, etc...).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...