SlideShare a Scribd company logo
6
Most read
8
Most read
10
Most read
Two dimensional lists
(arrays)
• https://www.scaler.com/topics/2d-array-in-python/
• https://snakify.org/en/lessons/two_dimensional_lists_arrays/
• https://www.geeksforgeeks.org/python-using-2d-arrays-lists-the-right
-way/
• Two Dimensional (2D) lists in Python is a nested data structure,
meaning it is a set of lists inside another list. The 2D list is mostly
used to represent data in a tabular or two-dimensional format.
• A 2D array in python is a two-dimensional data structure used for
storing data generally in a tabular format. For example, if you want to
store a matrix and do some computations, how would you do it in
Python?
Syntax of Python 2D Array
• Each element in a 2D array is represented by two indices, the row and
the column. 2D arrays in python are zero-indexed, which means
counting indices start from zero rather than one; thus, zero is the first
index in an array in python.
Syntax of Python 2D Array
• array_name=[[r1c1,r1c2,r1c3,..],[r2c1,r2c2,r2c3,...],. . . .]
• Where array_name is the array's name, r1c1, r1c1 etc., are elements
of the array. Here r1c1 means that it is the element of the first column
of the first row. A 2D array is an array of arrays.
• Example:
• # Define the two-dimensional list
• array_name = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
Accessing Values in Python 2D Array
• We can directly access values or elements of a 2D array in Python. It
can be done by using the row and column indices of the element to
be accessed. It has the following syntax:
• array_name[row_ind][col_ind]
• EX: # Accessing elements
• array_name = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
• print("Element at row 1, column 1:", array_name[0][0]) # Output: 1
print("Element at row 2, column 3:", array_name[1][2]) # Output: 6
print("Element at row 3, column 2:", array_name[2][1]) # Output: 8
• If an index exceeds the size, if the array is provided to this function, it
returns the index out of range error. Such indices are known as out
of bounds.
Traversing Values in Python 2D Array
• Traversing in a 2D array in python can be done by using a for a loop.
We can iterate through the outer array first, and then at each element
of the outer array, we have another array, our internal array
containing the elements. So for each inner array, we run a loop to
traverse its elements.
Example of Traversing
Inserting Values in Python 2D Array
• Inserting a value in an array means adding a new element at a given
index in the array and then shifting the remaining elements
accordingly.
1. Adding a New Element in the Outer Array.
arr1.insert(ind,arr_insert)
2. Adding a New Element in the Inner Array.
arr1[r].insert(ind,arr_insert)
Example of inserting values to outer value
Nested lists (Two dimensional lists for Python)
Inserting value to the inner list
Updating Values in Python 2D Array
• arr_name[r][c]=new_element
• It Single element and inner list update types
• Example: arr[1][2]=16 will update single element of list
Updating inner list
• If you want to update inner list
• new_arr=[10,11,12]
• arr[1]=new_arr
Nested lists (Two dimensional lists for Python)
Nested lists (Two dimensional lists for Python)
Nested lists (Two dimensional lists for Python)
Nested lists (Two dimensional lists for Python)
Nested lists (Two dimensional lists for Python)
Nested lists (Two dimensional lists for Python)
Nested lists (Two dimensional lists for Python)
Nested lists (Two dimensional lists for Python)
Ad

Recommended

PDF
Arrays jasdkfjaksldjfkajsdklfdjsfkdfdffff
kalsangstudies
 
PPTX
Array-single dimensional array concept .pptx
SindhuVelmukull
 
PPTX
NUMPY-2.pptx
MahendraVusa
 
PDF
Arrays in python
Lifna C.S
 
PPTX
object oriented programing in python and pip
LakshmiMarineni
 
PPTX
arraycreation.pptx
sathya930629
 
PDF
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 
PDF
Unit-5-Part1 Array in Python programming.pdf
582004rohangautam
 
PPTX
ARRAY OPERATIONS.pptx
DarellMuchoko
 
PPT
Array 31.8.2020 updated
vrgokila
 
PPTX
2D-Arrays
Sampad Kar
 
PDF
Arrays in python
moazamali28
 
PPTX
Python array
Arnab Chakraborty
 
PDF
numpy.pdf
DrSudheerHanumanthak
 
PPTX
Data structures: linear lists
ToniyaP1
 
PDF
arrays-130116232821-phpapp02.pdf
MarlonMagtibay2
 
PDF
array-191103180006.pdf
HEMAHEMS5
 
PPTX
Chapter 5-Numpy-Pandas.pptx python programming
ssuser77162c
 
PDF
11 1. multi-dimensional array eng
웅식 전
 
PPTX
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
PPTX
Unit 1 array based implementation
LavanyaJ28
 
PPT
Chapter 10.ppt
MithuBose3
 
PDF
Numpy.pdf
Arvind Pathak
 
PPTX
2D arrays
Mehedi Hasan Raju
 
PDF
Numpy - Array.pdf
AnkitaArjunDevkate
 
PPTX
datastructure concepts ppt-190327174340.pptx
JeevaMCSEKIOT
 
PPTX
Unit 3
GOWSIKRAJAP
 
PPT
Arrays
SARITHA REDDY
 
PDF
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
PPTX
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 

More Related Content

Similar to Nested lists (Two dimensional lists for Python) (20)

PPTX
ARRAY OPERATIONS.pptx
DarellMuchoko
 
PPT
Array 31.8.2020 updated
vrgokila
 
PPTX
2D-Arrays
Sampad Kar
 
PDF
Arrays in python
moazamali28
 
PPTX
Python array
Arnab Chakraborty
 
PDF
numpy.pdf
DrSudheerHanumanthak
 
PPTX
Data structures: linear lists
ToniyaP1
 
PDF
arrays-130116232821-phpapp02.pdf
MarlonMagtibay2
 
PDF
array-191103180006.pdf
HEMAHEMS5
 
PPTX
Chapter 5-Numpy-Pandas.pptx python programming
ssuser77162c
 
PDF
11 1. multi-dimensional array eng
웅식 전
 
PPTX
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
PPTX
Unit 1 array based implementation
LavanyaJ28
 
PPT
Chapter 10.ppt
MithuBose3
 
PDF
Numpy.pdf
Arvind Pathak
 
PPTX
2D arrays
Mehedi Hasan Raju
 
PDF
Numpy - Array.pdf
AnkitaArjunDevkate
 
PPTX
datastructure concepts ppt-190327174340.pptx
JeevaMCSEKIOT
 
PPTX
Unit 3
GOWSIKRAJAP
 
PPT
Arrays
SARITHA REDDY
 
ARRAY OPERATIONS.pptx
DarellMuchoko
 
Array 31.8.2020 updated
vrgokila
 
2D-Arrays
Sampad Kar
 
Arrays in python
moazamali28
 
Python array
Arnab Chakraborty
 
Data structures: linear lists
ToniyaP1
 
arrays-130116232821-phpapp02.pdf
MarlonMagtibay2
 
array-191103180006.pdf
HEMAHEMS5
 
Chapter 5-Numpy-Pandas.pptx python programming
ssuser77162c
 
11 1. multi-dimensional array eng
웅식 전
 
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Unit 1 array based implementation
LavanyaJ28
 
Chapter 10.ppt
MithuBose3
 
Numpy.pdf
Arvind Pathak
 
Numpy - Array.pdf
AnkitaArjunDevkate
 
datastructure concepts ppt-190327174340.pptx
JeevaMCSEKIOT
 
Unit 3
GOWSIKRAJAP
 

Recently uploaded (20)

PDF
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
PPTX
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
PDF
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
PDF
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
PDF
The Growing Value and Application of FME & GenAI
Safe Software
 
PDF
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PDF
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
PDF
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
PDF
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
PDF
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
PDF
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
PDF
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
PDF
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
PDF
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
PPTX
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
PDF
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
PDF
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
The Growing Value and Application of FME & GenAI
Safe Software
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Ad

Nested lists (Two dimensional lists for Python)

  • 3. • Two Dimensional (2D) lists in Python is a nested data structure, meaning it is a set of lists inside another list. The 2D list is mostly used to represent data in a tabular or two-dimensional format.
  • 4. • A 2D array in python is a two-dimensional data structure used for storing data generally in a tabular format. For example, if you want to store a matrix and do some computations, how would you do it in Python?
  • 5. Syntax of Python 2D Array • Each element in a 2D array is represented by two indices, the row and the column. 2D arrays in python are zero-indexed, which means counting indices start from zero rather than one; thus, zero is the first index in an array in python.
  • 6. Syntax of Python 2D Array • array_name=[[r1c1,r1c2,r1c3,..],[r2c1,r2c2,r2c3,...],. . . .] • Where array_name is the array's name, r1c1, r1c1 etc., are elements of the array. Here r1c1 means that it is the element of the first column of the first row. A 2D array is an array of arrays. • Example: • # Define the two-dimensional list • array_name = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
  • 7. Accessing Values in Python 2D Array • We can directly access values or elements of a 2D array in Python. It can be done by using the row and column indices of the element to be accessed. It has the following syntax: • array_name[row_ind][col_ind] • EX: # Accessing elements • array_name = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] • print("Element at row 1, column 1:", array_name[0][0]) # Output: 1 print("Element at row 2, column 3:", array_name[1][2]) # Output: 6 print("Element at row 3, column 2:", array_name[2][1]) # Output: 8
  • 8. • If an index exceeds the size, if the array is provided to this function, it returns the index out of range error. Such indices are known as out of bounds.
  • 9. Traversing Values in Python 2D Array • Traversing in a 2D array in python can be done by using a for a loop. We can iterate through the outer array first, and then at each element of the outer array, we have another array, our internal array containing the elements. So for each inner array, we run a loop to traverse its elements.
  • 11. Inserting Values in Python 2D Array • Inserting a value in an array means adding a new element at a given index in the array and then shifting the remaining elements accordingly. 1. Adding a New Element in the Outer Array. arr1.insert(ind,arr_insert) 2. Adding a New Element in the Inner Array. arr1[r].insert(ind,arr_insert)
  • 12. Example of inserting values to outer value
  • 14. Inserting value to the inner list
  • 15. Updating Values in Python 2D Array • arr_name[r][c]=new_element • It Single element and inner list update types • Example: arr[1][2]=16 will update single element of list
  • 16. Updating inner list • If you want to update inner list • new_arr=[10,11,12] • arr[1]=new_arr