I am new to python and I’m trying to write a simple word counter using a dictionary. I am wondering why the following code will not work:
while word != None:
wordObject = Word()
wordObject.setWord(word)
if dictionary.has_key(wordObject.getWord():
setCount = dictionary[wordObject.getWord()]
setCount.setCount()
If I leave this as is it never enters the if statement, if I put a key value in the has key method then it will enter the statement and say that I have invalid syntax on my setCount variable. I am trying to set that variable to the object stored at the key value in the dictionary I made and then increment the words count with the setCount method. Thanks.
I can’t see your whole code but can predict you must be having some method
setCountinwordObjectand falsely using a local variable. Changing towordObject.setCount()may help otherwise a simpleis enough to store the count.