Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAamir Mirza
25,077 PointsTreehouse 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)
1 Answer
KRIS NIKOLAISEN
54,971 PointsStrange. 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.
Edit
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.
Aamir Mirza
25,077 PointsAamir Mirza
25,077 PointsOh, how embarrassing, I forgot I played around with that. Thanks for catching my error for me. 😅