user5732284 user5732284 - 6 months ago 8
Python Question

How deal with 2D array in Python?

I want to have a 2D array, the first Parametre is the name of student and the second one is his result.

i try this :

listStudentResult = []
listStudentResult.append([])
listStudentResult[0].append("Alex")
listOfasinEan[0].append(20)

lisStudentResult.append([])
listStudentResult[1].append(Paul)
listStudentResult[1].append(15)


How can i have the result of Alex?
i don't want
listStudentResult[0][1]

i need something like

listStudentResult[0]["Alex"]

Answer

By looking at your requirement, I would suggest you to use dictionary in python.

To explain dictionary, I will take your example

listStudentResult = dict()
listStudentResult['Alex'] = 20
listStudentResult['Paul'] = 15

You can access the elements using listStudentResult['Alex'].