What's a middle third?


#1



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?

https://www.codecademy.com/en/courses/python-beginner-en-KAgt5/2/5?curriculum_id=4f89dab3d788890003000096


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

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


#2

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.


#3

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:


#4

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


#5

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.


#6

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