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 Python Collections (Retired) Slices Slice Functions

helmi al kindy
helmi al kindy
1,371 Points

My answer isn't getting accepted

I have tried solving the question on my pc and I get the expected answer but it won't pass over here.

slices.py
def first_4(q):
  return q[0:4]

def odds(w):
  return w[2::2]

1 Answer

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey

See. you are saying this.

Michigan.

string[start:stop:step]

Michigan[2::2]

says start at 2. That is c So we already missed the i which is technically 1. So that's an odd number.

do it like this.

def first_4(iterable):
  return iterable[0:4]

def odds(interable1):
  return interable1[1::2]

Now I am saying

Michigan

start at 1 which is really the i. So that is the first odd numbered character. Now I say only skip 1 letter so I get h which is 3. Which is another odd. I do this all the way to the end.

Not sure how yours worked above but do you get what I am saying?

Let me know!