dictionary error: list assignment index out of range

Vaduvoiu Tiberiu vaduvoiutibi at yahoo.com
Fri Jan 28 02:34:57 EST 2011


Hy everyone, I'm trying to learng python for a week or two and there's a thing 
that is really disturbing me as I do not understand what the problem is. I'm 
trying to use a dictionary to remember when a user has visited a city. Code is 
really basic:

in the class init method I added
self.visited = []

and in the function where i check if city was visited:
cityNumber = 1 #example
if (not cityNumber in self.visited):
    #do some stuff
    self.visited[cityNumber] = "true"

Apparently the last line causes the error: list assignment index out of range. I 
read that this is the simplest way to assign a value to a 
dictionary(dict[key]=value). So why is the error appearing?? Thanks a lot in 
advance



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110127/e8b62a51/attachment.html>


More information about the Python-list mailing list