problem with dictionaries

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Wed Apr 23 08:22:30 EDT 2008


kdwyer a écrit :
> On Apr 23, 12:16 pm, Simon Strobl <Simon.Str... at gmail.com> wrote:
(snip)
>> #!/usr/bin/python
>>
>> import sys
>>
>> frqlist = open('my_frqlist.txt', 'r')
(snip)
>> frq = {}
>>
>> for line in frqlist:
>>     line = line.rstrip()
>>     frequency, word = line.split('|')
>>     frq[word] = int(frequency)
>>
(snip)

> It works for me, save that you need to read the file into a list first

You don't, unless you're using an old python versions (I'd say 2.3 or 
older). Files are now their own iterators.




More information about the Python-list mailing list