小编Sea*_*ean的帖子

在Python中执行多个列表理解的最有效方法

考虑到这三个列表的理解,是否有比这三个故意的设置更有效的方法呢?我相信这种情况下的for循环可能是不好的形式,但是如果我要遍历rowaslist中的大量行,我感觉下面的效率不高。

cachedStopWords = stopwords.words('english')

rowsaslist = [x.lower() for x in rowsaslist]
rowsaslist = [''.join(c for c in s if c not in string.punctuation) for s in rowsaslist]
rowsaslist = [' '.join([word for word in p.split() if word not in cachedStopWords]) for p in rowsaslist]
Run Code Online (Sandbox Code Playgroud)

将所有这些组合成一条理解语句是否更有效率?我从可读性的角度知道这可能是一堆代码。

python list-comprehension nltk

3
推荐指数
1
解决办法
272
查看次数

标签 统计

list-comprehension ×1

nltk ×1

python ×1