赞
踩
- <span style="white-space:pre"> </span>D_Ascii = { } #this will save time about 0.1s
- D_Freq = { } #avoid create&destroy a pointer in for loop
- for index_Word in range(len(lines_Word)-2):
- index_AsciiHash = ord(lines_Word[index_Word][0]) #this one costs 1.4 s
- str_Key = lines_Word[index_Word][0:-1] + str_const_GLUE + lines_Word[index_Word+1][0:-1] #costs 1.4s
- #str_Key = f_glue_word(lines_Word[index_Word][:-1],lines_Word[index_Word+1][:-1]) #costs 2.5s
- str_NextWord = lines_Word[index_Word+2][:-1] #costs 0.5s
- D_Ascii = self.list_AsciiHash[index_AsciiHash] #datatype -- dict_AciiHash_Dict
- D_Freq = self.list_KeyFreq_Dict_asciihash[index_AsciiHash] #costs 0.5s
- if str_Key not in D_Ascii: #put "not in" in front of "in",save 0.4s, because in will cause extra judge
- D_Ascii[str_Key] = { str_NextWord : 1 }#costs 1.4s
- D_Freq[str_Key] = 1#555
-
- else:
- if str_NextWord in D_Ascii[str_Key]:#666
- D_Ascii[str_Key][str_NextWord]+=1#666
- else:#666
- D_Ascii[str_Key][str_NextWord]=1#666
- D_Freq[str_Key] += 1#555
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。