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
Post a Comment