problem with dictionaries

kdwyer kevin.p.dwyer at gmail.com
Wed Apr 23 08:28:12 EDT 2008


On Apr 23, 1:22 pm, Bruno Desthuilliers <bruno.
42.desthuilli... at websiteburo.invalid> wrote:
> 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.

*Fiddles with the interpreter for a moment*
So they are - I'd quite forgotten about that - thanks for the
reminder!

K



More information about the Python-list mailing list