Counting unique words in python

前端 未结 3 913
深忆病人
深忆病人 2020-12-19 10:15

In direct, my code so far is this :

from glob import glob
pattern = \"D:\\\\report\\\\shakeall\\\\*.txt\"
filelist = glob(pattern)
def countwords(fp):
    w         


        
3条回答
  •  感动是毒
    2020-12-19 10:28

    print len(set(w.lower() for w in open('filename.dat').read().split()))
    

    Reads the entire file into memory, splits it into words using whitespace, converts each word to lower case, creates a (unique) set from the lowercase words, counts them and prints the output

提交回复
热议问题