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 trialJuan Suarez
1,406 PointsODDS challenge on slices
def odds(n):
l = []
for e in n:
try:
if e % 2 == 1:
l.append(e)
except TypeError:
pass
return l
not sure why is not passing the challenge it works on sublime
def first_4(a):
l = a[:4]
return l
def first_and_last_4(a):
return a[:4]+a[-4:]
def odds(n):
l = []
for e in n:
try:
if e % 2 == 1:
l.append(e)
except TypeError:
pass
return l
1 Answer
Steven Parker
231,269 PointsBe careful about testing a challenge in an external REPL or editor.
If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.
In this case, the challenged asked you to return "every item with an odd index", but your code is return the items that have an odd value instead. The correct solution is also much simpler. You just need a slice with the proper parameters.