python单词什么意思,“逐字逐句”是什么意思?语法在Python中意味着什么?

I see the following script snippet from the gensim tutorial page.

What's the syntax of word for word in below Python script?

>> texts = [[word for word in document.lower().split() if word not in stoplist]

>> for document in documents]

解决方案

This is a list comprehension. The code you posted loops through every element in document.lower.split() and creates a new list that contains only the elements that meet the if condition. It does this for each document in documents.

Try it out...

elems = [1, 2, 3, 4]

squares = [e*e for e in elems] # square each element

big = [e for e in elems if e > 2] # keep elements bigger than 2

As you can see from your example, list comprehensions can be nested.


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部