Changing variable to integer

vertigo spam at spam.pl
Sun Dec 17 08:42:15 EST 2006


Hello

I receive such error:
File "p4.py", line 24, in PrintWordCountFloat
     print "%s %f" % (word,words[word])
TypeError: list indices must be integers

i call PrintWordCountFloat with hash table, keys are words(string) and  
values float.
This part of the code:

def PrintWordCountFloat(words):
     number = 0
     for word in words:
         print "%s %f" % (word,words[word]) #line 24
         number = number + 1
     print "Total words: %d" %(number)

My function displays whole table correctly, and after that i receive  
mentioned error.
Why ? Where is the problem  ?

Thanx



More information about the Python-list mailing list