SHARE
TWEET

Untitled

a guest Nov 8th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def build_ngram_counts(words,n):
  2.     d={}
  3.     for i in range(len(words)-n):
  4.         key=[]
  5.         for j in  range(n):
  6.             key.append(words[i+j])
  7.         temp_list=[[],[]]
  8.         for each_word in words:
  9.             if each_word==key[-1]:
  10.                 index=find_index(words,each_word)
  11.                 temp_list[0]=[words[u] for u in index]
  12.                    
  13.                                    
  14.                    
  15. #find the number of appearances STILL                  
  16.                        
  17.  
  18.         d[tuple(key)]=temp_list
  19.     print(d)                  
  20. def find_index(array,word_of_good): #used for function 3 build_n_gram
  21.     index=[]
  22.     for x in range(len(array)):
  23.         if word_of_good==array[x]:
  24.             index.append(x+1)
  25.     return index
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top