python删除文本中指定内容并统计每个字出现字数_如何使用Python对特定目录中的文本文件的唯一字数进行计数?...

im writing a report and I need to count unique words of text files.

My texts are in D:\shakeall and they're totally 42 files...

I know some about Python, but I don't know what to do now.

This is what I know how it works.

read files in directory

make up a list of words from texts

count total/unique words

all I know is this. and some about for, while, lists and indexes, variables, lists...

What I want to do is make my own function library and use it to get result.

I really appreciate any advice about my questions.

------p.s.

I really know almost nothing about Python. What I can only do is a simple math or printing words in a list..given topic is too hard for me. Sorry.

解决方案textfile=open('somefile.txt','r')

text_list=[line.split(' ') for line in textfile]

unique_words=[word for word in text_list if word not in unique_words]

print(len(unique_words))

That's the general gist of it

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值