Aamir Mirza23,362 Points
Treehouse says I "Didn't get the right string" even though I did?
The challenge is to find the longest string in the list using reduce() and lambda.
When I run this code in the terminal, it returns the grandma string, which I am pretty sure is the longest string in that list. But Treehouse says it didn't get the right string. I'm not sure what other output it could be expecting.
from functools import reduce strings = [ "Do not take life too seriously. You will never get out of it alive.", "My fake plants died because I did not pretend to water them.", "A day without sunshine is like, you know, night.", "Get your facts first, then you can distort them as you please.", "My grandmother started walking five miles a day when she was sixty. She's ninety-seven now and we don't know where she is.", "Life is hard. After all, it kills you.", "All my life, I always wanted to be somebody. Now I see that I should have been more specific.", "Everyone's like, 'overnight sensation.' It's not overnight. It's years of hard work.", ] longest = reduce(lambda x, y: x if len(x) >= len(y) else y, strings)
KRIS NIKOLAISEN53,389 Points
Strange. If I copy/paste just this line from your code:
longest = reduce(lambda x, y: x if len(x) >= len(y) else y, strings)
it passes. But if I copy/paste all the code it doesn't. Im looking for a difference in
strings but don't see one.
I found it. The original longest string has a misspelling of know
She's ninety-seven know and we don't know where she is.
Your string has it corrected to now:
She's ninety-seven now and we don't know where she is.
So it's not the same string.