[Tutor] about a dictionary use

Abdirizak abdi a_abdi406@yahoo.com
Mon Apr 21 13:33:02 2003


--0-675989952-1050942476=:35796
Content-Type: text/plain; charset=us-ascii

Hi,I have a program that uses a dictionary for indexing, the program reads several files, and and puts the words in the dictionary, after that it uses that dictionary and updates some values and puts in another dictionary: the question is if I want use the last dictionary for searching do I need to store it in a list such as "Shelve" so that I can access lateror I can keep the last dictionary for searching ? below is what have as a code: adict = {}
        temp = aword.findall(file.lower())        i = -1
        #print temp # prints a listfor test  #eliminate all stoplist words
        for word in temp:
            if word[0] != '<' and word not in stop_list:
                   
                    #print s # prints each word
                    i = i + 1      
                    #add the word tokens and their positions
                    #to dictionary
                    adict.setdefault(word,[]).append(i)           nwords = math.log(i + 1)          tempDict = {}
        for word, positions in adict.items():                
            # coumpute the word frequency
            frequency = int (100 * (len(positions) / nwords))
            
            # this dictionary puts the keys with multiple variables
            tempDict.setdefault(word,[]).append(key)
            tempDict.setdefault(word,[]).append(frequency)
            tempDict.setdefault(word,[]).append(positions)


---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
--0-675989952-1050942476=:35796
Content-Type: text/html; charset=us-ascii

<DIV>Hi,</DIV>
<DIV>I have a program that uses a dictionary for indexing, the program reads&nbsp;several files, and and puts the words in the dictionary, after that it&nbsp;uses&nbsp;that dictionary and updates&nbsp;some values and puts in another dictionary:&nbsp;the question is if I want&nbsp;use the last dictionary for searching do I&nbsp;need to store&nbsp;it in a list such as "Shelve" so that I can access later</DIV>
<DIV>or I can keep the last dictionary for searching ? below is what have as a code:</DIV>
<DIV>&nbsp;</DIV>
<DIV>adict = {}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp = aword.findall(file.lower())</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = -1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #print temp # prints a listfor test&nbsp; #eliminate all stoplist words<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for word in temp:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if word[0] != '&lt;' and word not in stop_list:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #print s # prints each word<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = i + 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #add the word tokens and their positions<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #to dictionary<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; adict.setdefault(word,[]).append(i)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nwords = math.log(i + 1)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempDict = {}</DIV>
<DIV><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for word, positions in adict.items():&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # coumpute the word frequency<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; frequency = int (100 * (len(positions) / nwords))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # this dictionary puts the keys with multiple variables<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempDict.setdefault(word,[]).append(key)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempDict.setdefault(word,[]).append(frequency)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempDict.setdefault(word,[]).append(positions)</DIV><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://us.rd.yahoo.com/search/mailsig/*http://search.yahoo.com">The New Yahoo! Search</a> - Faster. Easier. Bingo.
--0-675989952-1050942476=:35796--