Sorry for the unspecific title, but I was not able to explain it better.
I have this python code:
def longestWord_with_recursion(wrds):
if type(wrds) == str:
return len(wrds),wrds
return max([longestWord_with_recursion(x) for x in wrds])
(...)
words = [list of words]
print(longestWord_with_recursion(words))
The return with len(wrds),wrds gives me the following:
(11, 'programming') #programming is the correct answer
However, since I only want to return the word, I replace the return with return wrds, which gives me the following:
you #another word in the list, but the wrong one
Why does this happen? Why does it give me the correct word if I add another return value but not if I only return this one? And how could one fix this?
E: The list of words is:
['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']
maxfunction do?