count - Python- Write a function that opens a .txt file and returns the total number of words in it -


Was trying to do this for a while but for some reason I did not get my head around this simple code There is no need to worry about the punctuation marks, its just plain text. At the moment I have everything:

  def wc (filename): f = open (filename, 'r ') Read the word # f.readlines () f.close () print int (Filename.split ()) p = 1 for words in words: p + = word return  

An answer for a while Is looking for, but only they can count specific words where examples.

  f = open (file name) read # word = f.read () f. Close () word = words. Split () print LAN (word)  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -