Re: Writing dictionary output to a file

Discussion in 'Python' started by dont bother, Mar 6, 2004.

  1. dont bother

    dont bother Guest

    You did not get me:
    heres what I have to ask:

    "How to preserve this attribute -- line
    number/position of the word in the dictionary."
    For example: If I am comparing words in a message with
    the words in a dictionary, whenever there is a match,
    I want to record the corresponding location of the
    word in the dictionary.
    heres the code I am using for matching the words in
    the dictionary with the words in the message:

    for i in msg:
    if i in dct:
    try:
    vector += 1

    except:
    vector = 1


    How to I store the corresponding location of the word
    in the dictionary which is matching

    and then I will use this location as the key of the
    vector and the value is being computed by vector
    <I NEED TO CHANGE SOMETHING HERE>

    for v,i in enumerate(vector):
    vector /= a
    #print v,i, vector ; if u want to see the word
    too that was commmon
    print v,":",vector
    #print "\n"



    --- Peter Otten <> wrote:
    > dont bother wrote:
    >
    > > I have this dictionary output as per the format I
    > > desired :
    > > index : value

    >
    > > However, I want to write this to a file, instead

    > of
    > > just printing out to the std output.

    >
    > > for i, v in enumerate(dct):
    > > print i,":",v

    >
    > Here's how to print to a file instead of stdout:
    >
    > dest = file("tmp.txt", "w")
    > for i, v in enumerate(dct):
    > print >> dest, i, ":", v
    > dest.close()
    >
    > Peter
    > --
    > http://mail.python.org/mailman/listinfo/python-list



    __________________________________
    Do you Yahoo!?
    Yahoo! Search - Find what you’re looking for faster
    http://search.yahoo.com
     
    dont bother, Mar 6, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HNguyen
    Replies:
    4
    Views:
    2,453
    HNguyen
    Dec 21, 2004
  2. dont bother

    Writing dictionary output to a file

    dont bother, Mar 6, 2004, in forum: Python
    Replies:
    3
    Views:
    422
    simon place
    Mar 6, 2004
  3. dont bother
    Replies:
    2
    Views:
    320
    Ruud de Jong
    Mar 6, 2004
  4. dont bother

    RE: Writing dictionary output to a file

    dont bother, Mar 6, 2004, in forum: Python
    Replies:
    0
    Views:
    395
    dont bother
    Mar 6, 2004
  5. Mav
    Replies:
    22
    Views:
    386
Loading...

Share This Page