On Apr 23, 1:16 pm, Simon Strobl <[EMAIL PROTECTED]> wrote: > Hello, > > the idea of the following program is to parse a frequency list of the > form FREQUENCY|WORD, to store the frequency of a word in a dictionary > (and to do some things with this information later). > > I have done this many many times. Suddenly, it does not work any more: > The value frq[key] is different from the value that key has in the > file 'my_frqlist.txt'. > > I am using Python 2.5.1 > > Any hints? > > Simon > > ================================================ > > #!/usr/bin/python > > import sys > > frqlist = open('my_frqlist.txt', 'r') > > # my_frqlist looks like this: > # 787560608|the > # 434879575|of > # 413442185|and > # 395209748|to > # 284833918|a > # 249111541|in > # 169988976|is > > frq = {} > > for line in frqlist: > line = line.rstrip() > frequency, word = line.split('|') > frq[word] = int(frequency) > > for key in frq.keys(): > print key, frq[key]
there's nothing wrong with that section, just try this when building your dictionary... if word in frq: print 'Duplicated Word Found: %s' % word only possibility that I can think of, and that is logical, is that you have duplicate keys in your file. -- http://mail.python.org/mailman/listinfo/python-list