I want to count the total no of words in each line in a file and print them.I tried
with codecs.open('v.out','r',encoding='utf-8') as f:
for line in f.readlines():
words = len(line.strip(' '))
print words
the input file is:
hello
try it
who knows
it may work
the output that I get is:
6
7
10
12
but what I need is:
1
2
2
3
is there any function that I can use? I have to print the first word of each line in a file, and similarly print the middle word and the last word of the line into separate files.