Skip to content

Instantly share code, notes, and snippets.

@Xotabu4
Created February 23, 2016 19:33
Show Gist options
  • Select an option

  • Save Xotabu4/b02e1a35bf40a91518a4 to your computer and use it in GitHub Desktop.

Select an option

Save Xotabu4/b02e1a35bf40a91518a4 to your computer and use it in GitHub Desktop.
# coding=utf-8
file = open('C:\\file.txt', 'r', encoding ='utf-8')
lines = file.readlines()
file.close()
number_of_words_per_line = []
for line in lines:
line.replace(".","")
line.replace(",","")
line.replace("!","")
line.replace("?","")
line.replace("(","")
line.replace(")","")
line.replace('"',"")
words_in_line = line.split()
number_of_words_per_line.append(len(words_in_line))
print(number_of_words_per_line)
total_words = 0
for number in number_of_words_per_line:
total_words += number
print(total_words/len(lines))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment