Hello!  I'm creating a dictionary called keywords that has multiple entries 
each with a variable list of values eg.

keywords[1] = [1, 4, 6, 3]
keywords[2] = [67,2]
keywords[3] = [2, 8, 5, 66, 3, 23]
etc.

The keys and respective values (both are integers) are read in from a file.  
For each key, the value is append'ed until the next key.  Here is the code.

.............
>>> keywords = {}
>>> with open("x.txt", "r") as f:
    k=0
    for line in f.readlines():
            keywords[k], second = map(int, line.split())
            keywords[k].append(second)
            if keywords[k] != k:
                    k=k+1
   
Traceback (most recent call last):
  File "<pyshell#44>", line 5, in <module>
    keywords[k].append(second)
AttributeError: 'int' object has no attribute 'append'
.............

Any idea why I get this error?

Dinesh


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to