this relates to _nestors problem but im trying to expand it on my own
i have this code:
logfile = open("logfile.txt", "r").readlines()
KEYWORDS = ['test', 'text']
counterline = []
counter = 0
for line in logfile:
for word in line.split():
counter+=1
if word in KEYWORDS:
counterline.append(counter)
print word
print KEYWORDS
print counterline
but at the moment it outputs this:
test
text
test
['test', 'text']
[1, 2, 4]
which is what i want it to at the moment
but i would like it to output it like this:
test
text
test
{'test':[1,4], 'text':[2]}
how would i go about doing it?
if possible could it be the easiest method to understand? (so that i can understand and learn from it)