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 trial

Python Functional Python Functional Workhorses Map and Filter

Andy Hughes
Andy Hughes
8,479 Points

Chaining functions - i’m lost

Maybe it’s new year fuzz but I have no clue where to go with this challenge and everything I have tried results in “Bummer, Try Again!” I can’t find anything in the community section either.

I get that I’m supposed to be using Map() and Filter() somewhere. So my thinking is that I should be creating a function in step 1, that effectively loops through “birthdays” and compares them to “today”. Then if the number of years is 13 or greater, it returns a new iterable with those results.

That’s my thinking, but I just can’t seem to write anything that gives me the right result, or even a result that yields anything other than “Bummer, Try Again”. Which I will reiterate, is an entirely pointless message. :(

So wise owls, I could use a steer in the right direction.

Happy New Year :)

birthdays.py
import datetime

birthdays = [
    datetime.datetime(2012, 4, 29),
    datetime.datetime(2006, 8, 9),
    datetime.datetime(1978, 5, 16),
    datetime.datetime(1981, 8, 15),
    datetime.datetime(2001, 7, 4),
    datetime.datetime(1999, 12, 30)
]

today = datetime.datetime.today()


def is_over_13(datetime):
    return (map(today - birthdays = 13))

1 Answer

Hey Andy Hughes !

So what this question is asking you to do, is to create a function that takes in a datetime which you have done here (but we will need to change the word datetime to dt so that it doesn't confuse the python interpreter):

def is_over_13(dt):

Then we need to return "whether or not the difference between that datetime and today is 4745 days (13 years × 365 days, ignoring leap years) or more."

So what we are returning for this part challenge is (today - dt) which will get the difference between the passed in datetime and today. Then we need to access the .day in that datetime, and return whether it is >= 4745.

Hopefully that helps you move on to the next 2 sections. You will be using map and filter in the 3rd stage. Let us know if you are still stuck!

Andy Hughes
Andy Hughes
8,479 Points

Thank you Mel Rumsey for your comment. I finally managed to get part one correct. Originally, I did start with:

is_over_13(datetime):
    return (today - datetime)

At that point I think I just started to over complicate things by thinking it all needed to be one line of code so I was trying to do comprehension and math and I just confused myself even more.

Your comments, helped me to figure out that I needed first to acquire the difference and then to check that difference against the 13yrs. So I ended up with the below code, which passed step 1:

def is_over_13(dt):
    diff = (today - dt)
    return (diff.days >= 4745)

That’s what happens when you have a break of three weeks in between videos! :)

Thanks again for your help.