python - How to take an inputted file and count the letters in each word and print it -


i have text document of 7000 words have go through , count letters in each word. stuck on trying break each line @ '/n' , having count it. if point me in right direction, appreciated.

from string import *  def main():     fname = raw_input("enter filename: ")     infile = open(fname,'r')     lines = 0       line in infile.readlines():         lines = lines + 1         letters = line.split(line)         x = str(letters)          print len(x)         print line       print lines main() 

you don't need break file lines using linefeed, python you. in comment said file had 1 word per line, this:

line_count = 0 open("test.txt") f:     line in f:         line_count += 1         print len(line)         print line  print line_count 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -