Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

accessing 2d list in python

Two-dimensional lists can be accessed similar 
to their one-dimensional counterpart. Instead of providing 
a single pair of brackets [ ] we will use an additional set for 
each dimension past the first.

#The below code demonstrates

heights = [["Noelle", 61], ["Ali", 70], ["Sam", 67]]

#To access "Noelle" or her age, would type the following 

noelles_height = heights[0][1] 
print(noelles_height)

#This would print out:
61

Here are the index numbers to access data for the list heights:

Element	            Index
"Noelle"    	heights[0][0]
61	            heights[0][1]
"Ali"	        heights[1][0]
70	            heights[1][1]
"Sam"	        heights[2][0]
67	            heights[2][1]
Source by nullorempty.org #
 
PREVIOUS NEXT
Tagged: #accessing #list #python
ADD COMMENT
Topic
Name
2+6 =