Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Still getting a key error on the truncated string
  • Loading branch information
sib12004 committed Apr 21, 2016
1 parent b34d60d commit bc82545
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pagerank2.py
Expand Up @@ -80,7 +80,10 @@ finalRank = PageRank(P, initialVector, .85, incoming)
#turn this into a dictionary of final rank value : index
rankOrder = {}
for i in range(len(finalRank)) :
rankOrder[finalRank[i]] = i
string = str(finalRank[i]) #keys need to be a string
string = string[:10] #truncate to length 10
rankOrder[string] = i
print(list(rankOrder.keys())[0])

#now write the answer to a text file
file = open("ranking.txt", "w")
Expand All @@ -91,6 +94,9 @@ finalRank.sort()

for i in finalRank :
index = finalRank.pop()
index = str(index) #cast the index to a string
index = index[:10] #truncate to length 10
print(index)
file.write(index, urls[index])

file.close()
Expand Down

0 comments on commit bc82545

Please sign in to comment.