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

Create a function named is_over_13 that takes a datetime and returns whether or not the difference between that datetime

Lost in functions and date times.

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(dt):
    def date_string(dt):
        return dt.strftime("%B %d")
    birth_dates = map(date_string, filter(is_over_13, birthdays))

1 Answer

Ryan McGuire
Ryan McGuire
3,758 Points

So together without my messy comments def is_over_13(dt): difference=today-dt return difference.days>=4745

See below for thought process: Following the instructions and typing some code as I go.

Instruction: Create a function named is_over_13 that takes a datetime.

Now I know i need a function and its name and that it will take some "argument" so I type:

def is_over_13(dt): #I used dt but you could use x or y or asd.

Continuing to read: ....and returns whether or not the difference between that datetime and today is 4745 days or more (>=4745 days).

Let's add some more code. def is_over_13(dt): difference=today-dt #today is defined above, so we know we can use that. dt is the datetime coming in, so we can use that. difference we are just "making" or "declaring" now, you could also use the word delta or zxc if you want. return difference.days>=4745

from the question we see difference..... is 4745 days or more which means greater than or equal to AKA >=4745 days).

not sure where you got def date_string(dt):. Unless that is for next part of challenge it's not needed.