Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

2d list in python


ar = [[0 for j in range(m)] for i in range(n)]

Comment

2d list in python

def list_2D(r, c):
    l = []
    for i in range(r):
        x = [0] * c
        l.append(x)
    return l
Comment

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]
Comment

PREVIOUS NEXT
Code Example
Python :: normalize a distribution plot 
Python :: Count the number of Non-Missing Values in the DataFrame 
Python :: how to remove all line in file python 
Python :: drop columns by name 
Python :: postgtres settings.py setup with django 
Python :: Python Tkinter Scale Widget Syntax 
Python :: check if varible is emyt pyton 
Python :: how to combine sets using update() Function 
Python :: list of object in python 
Python :: opencv minimum of two images python 
Python :: Plot Multiple ROC Curves in Python 
Python :: python yellow 
Python :: django not configured pylint error fix 
Python :: ssd 1306 esp32 python 
Python :: pandas assign multiple columns 
Python :: Sending Data in Unstructured File Form 
Python :: make max function returning more than one value python 
Python :: json object type in python 
Python :: sort python dictionary with values of list by index of first one 
Python :: python two list into dictinaray list comprehension 
Python :: cgi in python; get() method 
Python :: Django forms I cannot save picture file 
Python :: django rotatingfilehandler 
Python :: choose a random snippet of text 
Python :: Add silence to the end of an MP3 python 
Python :: presto sequence example date 
Python :: pygame do you need to use int() for positions 
Python :: python 3.10.5 release date 
Python :: To install the C++ and Python Messaging APIs: 
Python :: python @property decorator 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =