problem with dictionaries

Simon Strobl Simon.Strobl at
Wed Apr 23 13:16:55 CEST 2008


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?




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]

More information about the Python-list mailing list