I can't see a pattern for the results that I'm having on the print. And I've already tried other solutions for this, but can't get it right =(
s = "hi hi hi, how are you? you you"
print(s)
s = s.replace('?','')
s = s.replace('!','')
s = s.replace(',','')
s = s.replace('.','')
l = s.split()
d = {}
for i, termo in enumerate(l):
if not d.get(termo):
d[termo] = []
d[termo].append(i+1)
print ('d:', d)
An example output:
d: {'you': [6, 7, 8], 'how': [4], 'are': [5], 'hi': [1, 2, 3]}
d: {'are': [5], 'hi': [1, 2, 3], 'how': [4], 'you': [6, 7, 8]}