How to iterate over space-separated ASCII file in Python

for-loop, loops, python

Solution

This code reads the space separated file.txt

f = open("file.txt", "r")
words = f.read().split()
for w in words:
    print w

Problem

Strange question here. I have a `.txt` file that I want to iterate over. I can get all the words into an array from the file, which is good, but what I want to know how to do is, how do I iterate over the whole file, but not the individual letters, but the words themselves. I want to be able to go through the array which houses all the text from the file, and basically count all the instances in which a word appears in it. Only problem is I don't know how to write the code for it. I tried using a for loop, but that just iterates over every single letter, when I want the whole words.

Original source