Writing dictionary output to a file
dont bother
dontbotherworld at yahoo.com
Sat Mar 6 05:51:07 EST 2004
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[i] += 1
except:
vector[i] = 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]
<I NEED TO CHANGE SOMETHING HERE>
for v,i in enumerate(vector):
vector[i] /= a
#print v,i, vector[i] ; if u want to see the word
too that was commmon
print v,":",vector[i]
#print "\n"
--- Peter Otten <__peter__ at web.de> 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 youre looking for faster
http://search.yahoo.com
More information about the Python-list
mailing list