Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Functional Python Functional Workhorses Filter

12,964 Points

Filter Challenge Task 2 of 2 Bummer: dt_2012 isn't a filter!

I am completely stuck on this challenge. I know my task 1 code doesn't allow dt_2012 to filter through anything, but I can't figure out how to make it filter friendly.

Here are the instructions:

Task 1: Write a function named is_2012 that accepts a single argument and returns whether that argument's year attribute is equal to 2012.

Task 2: Now create a variable named dt_2012 that uses filter() and is_2012 to return only the datetimes from dates that are from the year 2012.

Thanks in advance! :)

import datetime

dates = [
    datetime.datetime(2012, 12, 15),
    datetime.datetime(1987, 8, 20),
    datetime.datetime(1965, 2, 28),
    datetime.datetime(2015, 4, 29),
    datetime.datetime(2012, 6, 30),

def is_2012(argument):
    if argument.year == 2012:
        return True

def dt_2012(dates):
    return filter(is_2012, dates)

1 Answer

Steven Parker
Steven Parker
215,954 Points

Note that instruction say "Now create a variable named dt_2012 ..."

You're calling the filter function correctly, but you're defining another function named "dt_2012" instead of creating a variable with that name and assigning the filter result to it.

12,964 Points

Thanks Steven Parker! I can't believe I missed that. :D