Two-dimensional lists

https://www.codecademy.com/courses/learn-python-3/lessons/create-python-list/exercises/accessing-2-d-lists

Here are my code

class_name_test = [[“Jenny”, 90], [“Alexus”, 85.5], [“Sam”, 83], [“Ellie”, 101.5]]

sams_score = class_name_test[2][1]

print (sams_score)
#Code Stop
I don’t understand with that two dimensional list with that “sams_score = class_name_test[2][1]”. I know that 2 stands for but that 1 confuses one. Can anyone help me with it?
Thanks.

What does polling, test[2] yield us?

>>> test[2]
    [“Sam”, 83]
>>>

That is another list.

If we want the second value in that list, we need to poll it, as well:

>>> test[2][1]
    83
>>>
1 Like

sorry, I still don’t get it.

[
  ["Jenny", 90],
  ["Alexus", 85.5],
  ["Sam", 83],
  ["Ellie", 101.5]
]

It’s called a 2-D list (as in two-dimensional) because it has both a vertical axis and a horizontal axis. The first subscript selects the row (in the vertical), the second subscript selects the item in that row.

thank you, Thank You!

1 Like

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