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 Filter

i m getting Bummer: Try again on this task where am i going wrong?

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.

filters.py
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
        break
dt_2012 = filter(is_2012, dates)

4 Answers

Steven Parker
Steven Parker
231,072 Points

You really close, but a "break" is only used with a loop, and there's no loop here. Plus the indentation doesn't line up.

Just remove that line entirely and you'll pass the challenge.

i did what you advised @Steven Parker but i still get the error

just tried it and it worked i don't know what was wrong at first

gustavoalvarado
seal-mask
.a{fill-rule:evenodd;}techdegree
gustavoalvarado
Python Development Techdegree Student 9,427 Points

Thabang Richard Katlholo I looked at Steven Parker's advice (thanks by the way) and i fixed my code this way

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),
]
# Part 1
def is_2012(argument):
    if argument.year == 2012:
# The last mistake that made me lose patience and look for help, i typed
# datetime.datetime.year instead of argument.year
        return True
    else:
        return False

And thanks to you Thabang Richard Katlholo, your code also helped mine.