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 trialnakalkucing
12,964 PointsFilter 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
231,268 PointsNote 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.
nakalkucing
12,964 Pointsnakalkucing
12,964 PointsThanks Steven Parker! I can't believe I missed that. :D