yield的一种简单用法

python中yield的用法
https://blog.csdn.net/mieleizhi0522/article/details/82142856

class Find_words:
	def __init__(self, min_count=10, max_count=100000):
		self.min_count = min_count
		self.max_count = max_count
		self.total = 0.
	def text_filter(self, texts):
		for a in texts:
			for t in re.split(u'[^\u4e00-\u9fa50-9a-zA-Z]+', a):
				if t:
					print('***')
					yield t
	def count(self, texts):
		for text in self.text_filter(texts):
			print(text)
	
if __name__ == '__main__':
	fw = Find_words(1,100000)
 	all_sentences = ["大家好","我是小田老师","我来自中国"]
	fw.count(all_sentences)

输出结果如下所示

***
大家好
***
我是小田老师
***
我来自中国
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值