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

Expected output (stage 2 on slices) is "kaoa"? Where exactly does “kaoa” comes from?

I just executed my code for task 2 on SLICES and I the result says: "Bummer! odds() didn't return the right output. Got [1, 3, 5, 7, 9], expected kaoa"

I honestly thought expected output was [1, 3, 5, 7, 9] so code is doing what I wanted to do but maybe I’m not understanding the question. Where exactly does “kaoa” comes from?

slices.py
def first_4(i):
    eliter =  list(range(10))
    return(eliter[1:5])

def odds(i):
    eliter =  list(range(10))
    return(eliter[1::2])

5 Answers

boog690
boog690
8,987 Points

Oklahoma is the input, let's call it state. The letters at odd indexes (1, 3, 5, 7) in state spell "kaoa".

Oh..., that worked. Where in instructions did I missed that "Oklahoma" was the input?.. strange.. but thanks.

boog690
boog690
8,987 Points

Well, I just assumed it was "Oklahoma" from the "kaoa." The input can be anything. The function should always return the letters (concatenated as a string) at the odd indices of any word.

awesome thanks.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You're taking arguments, i in both cases, and then completely ignoring them :) Don't ignore your arguments!

Thank you so much Kenneth.

I agree with the original poster here, I was also just using numbers in this code challenge because nothing about the prompt states to use "Oklahoma." Might want to have that added to the prompt. This is what it says currently:

"Make a function named odds that accepts an iterable as an argument and returns the items with an odd index in the iterable."

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Adding "Oklahoma" to prompt makes it really easy to fake the output if someone really wanted to cheat the validator. Also, strings are iterables just like lists and dicts and tuples are. The function should be able to handle any and all iterables.

Ahh, that makes a lot of sense Kenneth. I didn't think about the possibility of cheating the validator.

It's easy enough to figure out if your function is handling iterables, but at first I was confused as to why there wasn't a hint as to what string the validator was looking for if it wanted such a specific return value. Thanks for the persecptive!