I am trying to count the number of “hard words” in a file, which requires me to count the number of letters in each word. For now, I'm only trying to get individual words, one at a time, from a file. I wrote the following:
file = open('infile.txt', 'r+')
fileinput = file.read()
for line in fileinput:
for word in line.split():
print(word)
Output:
t
h
e
o
r
i
g
i
n
.
.
.
It seems to print one character at a time, and not one word at a time. I would really like to know more about what is really happening here. Any suggestions?
source
share