texts=[[word for word in document.lower().split() if word not in stoplist] for document in documents]
这段代码等同于:
texts=[]
for document in documents:
words=[]
for word in document.lower().split():
if word not in stoplist():
words.append(word)
texts.append(words)


python 中 counter用法
---------------------------
>>>from collections import Counter
>>>c = Counter()
>>>for ch in 'programing':
... c[ch]=c[ch]+1
>>>c
Counter({'g': 2, 'r': 2, 'a': 1, 'i': 1, 'm': 1, 'o': 1, 'n': 1, 'p': 1})
counter 是一个简单的计数器,比如统计字符出现的个数
--------------------- -----
python 中 json使用方法
一、概念理解
1、json.dumps()和json.loads()是json格式处理函数(可以这么理解,json是字符串)
(1)json.dumps()函数是将一个Python数据类型列表进行json格式的编码(可以这么理解,json.dumps()函数是将字典转化为字符串)
(2)json.loads()函数是将json格式数据转换为字典(可以这么理解,json.loads()函数是将字符串转化为字典)
2、json.dump()和json.load()主要用来读写json文件函数
二、代码测试
1.py
运行截图:

2.py
运行截图:

3.py
运行截图(1.json文件):

4.py
运行截图:
