I'm having trouble returning proper results for an inverted index in python. I'm trying to load a list of strings in the variable 'strlist' and then with my Inverse index looping over the strings to return the word + where it occurs. Here is what I have going so far:
def inverseIndex(strlist):
d={}
for x in range(len(strlist)):
for y in strlist[x].split():
for index, word in set(enumerate([y])):
if word in d:
d=d.update(index)
else:
d._setitem_(index,word)
break
break
break
return d
Now when i run inverseIndex(strlist)
all it returns is {0:'This'}
where what I want is a dictionary mapping all the words in 'strlist'
to the set d
.
Is my initial approach wrong? am i tripping up in the if/else? Any and all help is greatly appreciated. to point me in the right direction.