count word per sentence python

Solutions on MaxInterview for count word per sentence python by the best coders in the world

showing results for - "count word per sentence python"
Miguel Ángel
15 Jul 2017
1import nltk
2#nltk.download('punkt')
3from nltk.tokenize import sent_tokenize
4
5def count_lines(file):
6    count=0
7    myfile=open(file,"r")
8    string = ""
9
10    for line in myfile:
11        string+=line  
12        print(string)
13
14    number_of_sentences = sent_tokenize(string)
15
16    for w in number_of_sentences:
17        count+=1
18        print("Sentence ",count,"has ",len(w),"words")
19
20count_lines("D:\Atharva\demo.txt")