这里如果min_count和max_count都传了的话,会不会统计多次
来源:6-6 数据处理-句子编码化处理(训练字典)

竹千代与吉法师
2018-11-20
if min_count is not None:
count = {k:v for k, v in count.items() if v > min_count};
if max_count is not None:
count = {k:v for k,v in count.items() if v <= max_count};
这里如果min_count和max_count都传了的话,中间的那部分区域统计了两次,两边的区域分别统计了一次?
写回答
2回答
-
你好!我没看懂这几行和前面的那段代码是什么意思,可以向你请教一下吗?
我不是很明白建立count这个词典的用途,这个词典是用来做什么的?
以及这两行if是在做什么?
count = {}
for sentence in sentences:
arr = list(sentence)
for a in arr:
if a not in count:
count[a] = 0
count[a] += 1
if min_count is not None:
count = {k: v for k, v in count.items() if v >= min_count}
if max_count is not None:
count = {k: v for k, v in count.items() if v <= max_count}022018-12-05 -
竹千代与吉法师
提问者
2018-11-20
哦 这个是限制了两次长度 我之前以为是在循环内做的 没太懂代码之前,回头看发现这是两种截取操作,互不影响
00
相似问题