I have a text file that may look like this...
3:degree
54:connected
93:adjacent
54:vertex
19:edge
64:neighbor
72:path
55:shortest path
127:tree
3:degree
55:graph
64:adjacent and so on....
I want to have my function read each line of text, and split it at the colon to make it into a dictionary where the word is in 'key' position and the page numbers are in the 'value' position of my dictionary- I'll then have to create a new dictionary and scan through each word and if it's already in the dictionary just add the page number behind it and if it's not in the dictionary, I'll add it to the dictionary.
This is my idea so far...
def index(fileName):
inFile=open(fileName,'r')
index={}
for line in inFile:
line=line.strip() #This will get rid of my new line character
word=line[1]
if word not in index:
index[word]=[]
index[word].append(line)
return index
fileName='terms.txt'
print(index(fileName))
I'm on the right page but just need a little help to get going.