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

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -