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 trialgibran erlangga
5,539 Pointsmake odd index in iterable question
Need a little help here guys.
I'm trying to solve this problem, but I'm stuck with this.
Any help will be highly appreciated. Thanks!
def first_4(iterab):
return iterab[:4]
def odds(iterab):
a = iterab%2
if a != 0:
return odds
1 Answer
Jennifer Nordell
Treehouse TeacherHi gibran erlangga! You're doing great and I can see you've given this some thought. But before I show you how I did it, let's take a moment and look at some things in your code first. Your odds function is trying to return itself. Also your variable a
is not looking at the index of a place in your iterab
variable. It's looking at the entire iterable. That being said, here's what you need:
def odds(iterab):
return iterab[1::2]
This will start at the first index in our iterable. Remember the iterable has a 0 index, but we don't want that one. Then it will go down to the end of the iterable by steps of 2. So every other one Hope this helps!