-1

我正在尝试从生成器获取实际输出,但我将输出作为生成器对象。请帮我实现生成器的实际输出

import spacy
nlp = spacy.load('en')

def lemmatizer(words):
     yield from [w.lemma_ for w in nlp(words)]

list1 = ['birds hanging on street','people playing cards']

a = list(map(lemmatizer,list1))

输出:

a
[<generator object....>,
<generator object....>]

预期输出:

a
['birds hang on street',
'people play card']
4

2 回答 2

1

在@PatrickArtner 评论的帮助下,这对我有用

a = list(map(list, map(lemmatizer,list1)))
b = list(map(' '.join, a))
于 2021-12-28T13:15:05.900 回答
-1

用于next从生成器中产生。添加next喜欢a = list(next(map(lemmatizer,list1)))应该工作。

import spacy
nlp = spacy.load('en')

def lemmatizer(words):
     yield from [w.lemma_ for w in nlp(words)]

list1 = ['birds hanging on street','people playing cards']

a = list(next(map(lemmatizer,list1)))
于 2021-12-28T10:53:20.850 回答