我有一个Python的问题。 我想了解哪些是存储在我发现是一个生成器的对象中的信息。 我对Python一无所知,但我必须了解这段代码如何工作才能将其转换为Java。 代码如下:python嵌套生成器对象内容
def segment(text):
"Return a list of words that is the best segmentation of text."
if not text: return []
candidates = ([first]+segment(rem) for first,rem in splits(text))
return max(candidates, key=Pwords)
def splits(text, L=20):
"Return a list of all possible (first, rem) pairs, len(first)<=L."
pairs = [(text[:i+1], text[i+1:]) for i in range(min(len(text), L))]
return pairs
def Pwords(words):
"The Naive Bayes probability of a sequence of words."
productw = 1
for w in words:
productw = productw * Pw(w)
return productw
,而我的理解是怎么方法Pwords并分割工作(功能Pw的(W)只要从一个矩阵的值),我还是想知道,如何“候选人“对象,在”细分“方法中构建并包含它。 以及“max()”函数如何分析此对象。
我希望有人能帮助我,因为我没有找到任何可行的解决方案来打印此对象。 非常感谢大家。 毛罗。
可能重复替换嵌套发电机[在Python了解发电机?(http://stackoverflow.com/questions/1756096/understanding-generators -in-python)相关问题:[Python yield关键字解释](http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained) – Bakuriu