Skip to content

Instantly share code, notes, and snippets.

@figengungor
Created September 29, 2013 13:49
Show Gist options
  • Select an option

  • Save figengungor/6752683 to your computer and use it in GitHub Desktop.

Select an option

Save figengungor/6752683 to your computer and use it in GitHub Desktop.
A function that reads a file and returns the number of lines and words in the file as a tuple.
def number_of_lines_and_words_of_the_file(filename):
f = open(filename)
lineNo=0
wordNo=0
for line in f:
wordNo+=len(line.split(" "))
lineNo+=1
return lineNo, wordNo
print number_of_lines_and_words_of_the_file("series.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment