input file input txt words for num line in enumerate input chunks line

1
2
3
4
5
6
7
input = file('input.txt')
words = {}
for num, line in enumerate(input):
chunks = line.strip().split()
for chunk in chunks:
words.setdefault(chunk, []).append(num)