FAQ: Introduction to Lists in Python - Modifying 2D Lists

thanks, this explanation helped a lot

Wow codecademy should really explain how it reads in the course. This made it click instantly for me. Thank you so much

1 Like

I am a little confused. when editing the list I get the using [1][2] will edit the 2nd member and their 2nd sub.

But when I only need to change one item that is a name i am using the below code. why won’t that work with Ken when just using [-3]? why do I need to have [-3][-3]? I am just confused on why I need both negative indices if I am just editing the first portion.

#Your code below:

incoming_class = [[“Kenny”, “American”, 9], [“Tanya”, “Russian”, 9], [“Madison”, “Indian”, 7]]

incoming_class[2][2] = 8

incoming_class[-3] = “Ken”

print(incoming_class)

That statement will overwrite ['Madison', 'Indian', 7] with 'Ken', which destroys whatever homogeneity the original list had.

doubt in indexing
incoming_class=[[“Kenny”,“American”,9],[“Tanya”,“Russian”,9],[“Madison”,“Indian”,7]]

print(incoming_class)

incoming_class[2][2]=8

print(incoming_class)
how index[2][2]

incoming_class = [["Kenny","American",9], ["Tanya","Russian",9], ["Madison","Indian",7]]

Here, incoming_class[2] would be ["Madison","Indian",7]
and for that inner list, [2] would be 7
so incoming_class[2][2] is 7

I think this a bug. I’m getting the correct result but the course is calling it incorrect:

"Madison" passed an exam to advance a grade. She will be pushed into 8th grade rather than her current 7th in our list.

incoming_class = [["Kenny",	"American",	9], ["Tanya",	"Russian",	9], ["Madison",	"Indian",	7]]

##print (incoming_class)

#print (incoming_class [2] [2])

incoming_class [2] [2] = 8

print (incoming_class)

This turns out to be a spacing issue.

incoming_class [2] [2] = 8 needs to be incoming_class[2][2] = 8 in order to this to be considered correct by the course. This seems to me to be a bug. Unsure how CA devs will view that though.

I assume this was a recent change. Instruction 1 tells us that Tanya’s nationality is Ukranian, but the code check expects her nationality to be Russian. So either the instructions need to be changed or the code check needs to update to the new instructions. Hope this helps someone down the road.

1 Like

Agreed. This concept was tricky for me to understand. @codecademy should do a better job of explaining this in the lesson.

1 Like

Hello, please clarify on ques 3: Why can’t we use [0][0] instead of [-3][-3]? as it gives the same result- “Ken”

incoming_class [0][0] = “Ken”

print(incoming_class)

They are coincidental, but in point of fact, we don’t know how far from the right edge [0][0] is. We know exactly how far from the right edge [-3][-3] is, however.

Hey guys, i have a question in regards to the Madison problem. Its telling me to change the last element in the list [“Madison”, “Indian”, 7]

The way i mapped it was, i would type list_variable[0][0][0] = 8
however i got it wrong. I am confused on why its not how it is above and instead the correct answer is list_variable[0][0] = 8

I know its not a crazy big concern but it gives me anxiety because i cant help but think how crazy lists are in the real world and what if i do have to change an element in a list that has like 5 elements within one individual list within a list.

1 Like

Have a look at this post.

https://discuss.codecademy.com/t/faq-introduction-to-lists-in-python-accessing-2d-lists/576656/23

In the linked post, the two-dimensional list is class_name_test with a structure of:

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

If you still find something confusing, share your thoughts.

Hi, I am on the Python 3 Modules working on an exercise called “Modifying 2D Lists”.

Here is the objective

Our school is expanding! We are welcoming a new set of students today from all over the world.

Using the provided table, create a two-dimensional list called incoming_class to represent the data. Each sublist in incoming_class should contain the name, nationality, and grade for a single student.

|Name|Nationality|Grade Level|
| — | — | — |
|"Kenny"|"American"|9|
|"Tanya"|"Ukrainian"|9|
|"Madison"|"Indian"|7|

Print incoming_class to see our list.

Here is the code that I have

incoming_class = [[“Kenny”, “American”, 9], [“Tanya”, “Ukranian”, 9], [“Madison”, “Indian”, 7]]

print(incoming_class)

Unfortunately, it doesn’t work and Codecademy marked it as wrong. I am not sure what I did. But I know for a fact that my solution is correct…

any suggestions???

I assume that you are seeing the following SCT error:
image

The output needs to match exactly. Your output does not match the expected output. Check your spelling.

1 Like

@tgrtim I assume in this case, you meant print(temp[1])?

1 Like

Im sure I missed somewhere in the lesson Please help explain why in the code below incoming_class[-3][-3] = “Ken” selects the first sublist and then also selects the third item in it.

How does [-3][-3] select the first sublist and third item in the sublist.

Code:
incoming_class = [[“Kenny”, “American”, 9], [“Tanya”, “Ukrainian”, 9], [“Madison”, “Indian”, 7]]
incoming_class[-3][-3] = “Ken”

Negative indices read from the right. “Kenny” is in the third from the right inner object of the parent list. The sublist index -3 does not exist.

Wouldn’t Kenny’s Set then be -2 instead if we start from 0.
Or do we not start from 0 when going negative indices and also not when going right to left?