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

Dara Roberts
PLUS
Dara Roberts
Courses Plus Student 7,770 Points

Not sure what is wrong with birth_dates variable.

I'm not sure where I'm going wrong with this

birth_dates = map(date_string filter(is_over_13, birthday))

I'm sure I've missed something silly. Any help is appreciated.

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):
    delta = today - dt 
    return delta.days >= 4745

def date_string(dy): 
    string = dy.strftime("%B %d") 
    return string 
print(date_string(today))

birth_dates = map(date_string filter(is_over_13, birthday))

1 Answer

Eric M
Eric M
11,546 Points

Hi Dara,

This is great work, you're just missing a comma and an 's'!

birth_dates = map(date_string, filter(is_over_13, birthdays))

Keep in mind that despite their power map and filter are just functions that take two arguments. A function and an interable. They can be chained because they also return iterables. So the arguments for filter are the is_over_13 function and the birthdays iterable. The arguments for map are the date_string function and the iterable returned by filter.

Probably you already know that and this was just a typo. The time we spend chasing typos we can't see in programming can be frustrating, but at least means all your logic was correct!

Cheers,

Eric

Dara Roberts
Dara Roberts
Courses Plus Student 7,770 Points

I knew it was going to be something like that! Thanks so much for seeing the little details that I couldn't :)