回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>对不起,这个不具体的标题,但我无法更好地解释它。你知道吗</p>
<p>我有这个python代码:</p>
<pre><code>def longestWord_with_recursion(wrds):
if type(wrds) == str:
return len(wrds),wrds
return max([longestWord_with_recursion(x) for x in wrds])
</code></pre>
<p>(…)</p>
<pre><code>words = [list of words]
print(longestWord_with_recursion(words))
</code></pre>
<p>带有<strong>len(wrds),wrds</strong>的返回给我以下信息:</p>
<pre><code>(11, 'programming') #programming is the correct answer
</code></pre>
<p>但是,由于我只想返回单词,因此我将返回替换为<strong>return wrds</strong>,它给出了以下内容:</p>
<pre><code>you #another word in the list, but the wrong one
</code></pre>
<p>为什么会这样?如果我加上另一个返回值,但如果我只返回这个值,为什么它会给我正确的单词?怎么能解决这个问题呢?你知道吗</p>
<p>E:单词列表是:</p>
<blockquote>
<p>['The', 'Scandal', 'of', 'education', 'is', 'that', 'every', 'time', 'you', 'teach', 'something', 'you', 'deprive', 'a', 'student', 'of', 'the', 'pleasure', 'and', 'benefit', 'of', 'discovery', 'Seymour', 'Papert', 'born', 'February', '29', '1928', 'died', 'July', '31', '2016', 'If', 'debugging', 'is', 'the', 'process', 'of', 'removing', 'bugs', 'then', 'programming', 'must', 'be', 'the', 'process', 'of', 'putting', 'them', 'in', 'Edsger', 'W', 'Dijkstra']</p>
</blockquote>