What's a middle third?

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

The lesson asks me to create a list called middle_third that’s equal to another list called to_21. But… what’s a middle third?
<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/python-beginner-en-KAgt5/2/5?curriculum_id=4f89dab3d788890003000096

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>

I don't think this is necessary but here's my code so far ```python

to_21 = [x for x in range(1,22)]
odds = to_21[::2]
middle_third = [

<do not remove the three backticks above>
2 Likes

This is our to_21 list:

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]

Middle third is the middle part of the list when you divide it to three, equal length parts.

to_21 has 21 elements, so we have to create three parts with seven elements each:

[
    [1, 2, 3, 4, 5, 6, 7],
    [8, 9, 10, 11, 12, 13, 14],
    [15, 16, 17, 18, 19, 20, 21]
]

The middle part is what you were asked to generate. And this is clearly stated in the instructions:

Finally, create a third list, middle_third, that’s equal to the middle third of to_21, from 8 to 14, inclusive.

4 Likes

Middle_third is a list.
As for your code, it is pretty good, except your to_21 list could be just like this:

to_21 = range(1,22)

middle_third should look like this:

middle_third = to_21[7:14]

and then print all of the lists hope this helps. :grin:

1 Like

Just wondering why its 7:14 and not 8:15? I thought the start index was inclusive and the end was exclusive?

That’s true, but we work on the indices, not values.

We want to get values from 8 (inclusive) to 15 (exclusive).

Value 8 is at the index 7 and value 15 is at index 14.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.