The Python code _python the number of English words in the same cloth

Source: Internet
Author: User
Word for English words in the statistics are also very good, you may wish to try. If Word is not installed and you are also a program member, you can use my code. Pass the test, Word's statistic result is 18674, the software statistic result is 18349, the difference is less than 2%, can serve as a reference.

The code is as follows:
Copy Code code as follows:

#-*-Coding:utf-8-*-

Import Os,sys
info = OS.GETCWD () #获取当前文件名称
Fin = open (U ' Google C + + programming code specification. txt ')

info = Fin.read ()
Alist = Info.split (') # to divide the article by space

Fout = open (U ' count.txt ', ' W ')
Fout.write (' \ n '. Join (alist) # can see the same effect through the line number of the text file
# #fout. Write ('%s '% alist)
Fout.close ()

Allen = Len (alist) # total number of words
Nulen = number of spaces in Alist.count (') #
print "Words ' number is", Allen
Print "null number is", Nulen
Print "Poor words number is", Allen-nulen # actual words

Fin.close ()
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.