你有一个目录,放了你一个月的日记,都是 txt,为了避免分词的问题,假设内容都是英文,请统计出你认为每篇日记最重要的词。

    技术2022-07-13  79

    import os def word(filename, w): for item in os.listdir(filename): # 打开文件 print(item) s = 0 with open(os.path.join(filename, item), 'rb') as f: total = f.read().decode('utf-8') for line in total.split(): if w in line: s += 1 print(s) word('D:\python练习题\python实战', 'for')
    Processed: 0.019, SQL: 9