SlideShare a Scribd company logo
1 of 10
Module 2
Data Collections – Lists, Tuples,
and Dictionaries
Multidimensional arrays
Module 2 Multidimensional arrays
Lists in lists
row = []
for i in range(8):
row.append(WHITE_PAWN)
row = [WHITE_PAWN for i in range(8)]
squares = [x ** 2 for x in range(10)]
#output [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
twos = [2 ** i for i in range(8)]
#output [1, 2, 4, 8, 16, 32, 64, 128]
squares = [x ** 2 for x in range(10)]
odds = [x for x in squares if x % 2 != 0 ]
print(odds)
#output [1, 9, 25, 49, 81]
Module 2 Multidimensional arrays
Two-dimensional arrays
board = []
for i in range(8):
row = [EMPTY for i in range(8)]
board.append(row)
EMPTY = "-"
ROOK = "ROOK"
board = []
for i in range(8):
row = [EMPTY for i in range(8)]
board.append(row)
board[0][0] = ROOK
board[0][7] = ROOK
board[7][0] = ROOK
board[7][7] = ROOK
print(board)
board = [[EMPTY for i in range(8)] for j in range(8)]
Module 2 Multidimensional arrays
Multidimensional nature of lists
two
coordinates
a vertical one
(row number)
a horizontal
one (column
number)
temps = [[0.0 for h in range(24)] for d in range(31)]
# The matrix is magically updated here.
total = 0.0
for day in temps:
total += day[11]
average = total / 31
print("Average temperature at noon:", average)
The monthly average noon temperature
Module 2 Multidimensional arrays
Multidimensional nature of lists
temps = [[0.0 for h in range(24)] for d in range(31)]
# The matrix is magically updated here.
highest = -100.0
for day in temps:
for temp in day:
if temp > highest:
highest = temp
print("The highest temperature was:", highest)
The highest temperature
Module 2 Multidimensional arrays
Multidimensional nature of lists
temps = [[0.0 for h in range(24)] for d in range(31)]
# The matrix is magically updated here.
hot_days = 0
for day in temps:
if day[11] > 20.0:
hot_days += 1
print(hot_days, "days were hot.")
The days when the temperature at noon was at least 20 ℃
Module 2 Multidimensional arrays
Three-dimensional arrays
• three buildings
• 15 floors each
• 20 rooms on each floor
the type of the array's elements(True/False)
calm analysis of the situation
rooms = [[[False for r in range(20)] for f in
range(15)] for t in range(3)]
In the second building,
on the tenth floor, room
14:
rooms[1][9][13] = True
Module 2 Multidimensional arrays
Key takeaways 1
[expression for element in list if conditional]
# A four-column/four-row table - a two
dimensional array (4x4)
table = [[":(", ":)", ":(", ":)"],
[":)", ":(", ":)", ":)"],
[":(", ":)", ":)", ":("],
[":)", ":)", ":)", ":("]]
print(table)
print(table[0][0]) # outputs: ':('
print(table[0][3]) # outputs: ':)'
list comprehension
use nested lists to
create matrices
Module 2 Multidimensional arrays
Key takeaways 2
# Cube - a three-dimensional array (3x3x3)
cube = [[[':(', 'x', 'x'],
[':)', 'x', 'x'],
[':(', 'x', 'x']],
[[':)', 'x', 'x'],
[':(', 'x', 'x'],
[':)', 'x', 'x']],
[[':(', 'x', 'x'],
[':)', 'x', 'x'],
[':)', 'x', 'x']]]
print(cube)
print(cube[0][0][0]) # outputs: ':('
print(cube[2][2][0]) # outputs: ':)'
create n-dimensional
lists
Congratulations!
You have completed Module 2
Well done! You've reached the end of Module 2
and completed a major milestone in your Python
programming education.

More Related Content

What's hot

Derivative investigation
Derivative investigationDerivative investigation
Derivative investigation
jchartiersjsd
 
Day 7 examples u6w14
Day 7 examples u6w14Day 7 examples u6w14
Day 7 examples u6w14
jchartiersjsd
 
How to graph Functions
How to graph FunctionsHow to graph Functions
How to graph Functions
coolhanddav
 

What's hot (18)

Coding Test Review1
Coding Test Review1Coding Test Review1
Coding Test Review1
 
Derivative investigation
Derivative investigationDerivative investigation
Derivative investigation
 
Lr5
Lr5Lr5
Lr5
 
Fungsi kuadrat
Fungsi kuadratFungsi kuadrat
Fungsi kuadrat
 
Examen final (2 d 10)
Examen final (2 d   10)Examen final (2 d   10)
Examen final (2 d 10)
 
10.5 more on language of functions x
10.5 more on language of functions x10.5 more on language of functions x
10.5 more on language of functions x
 
Matlab ploting
Matlab plotingMatlab ploting
Matlab ploting
 
Function
FunctionFunction
Function
 
Day 6 examples
Day 6 examplesDay 6 examples
Day 6 examples
 
Lecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional ArrayLecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional Array
 
Coding test review
Coding test reviewCoding test review
Coding test review
 
1 13s-f
1 13s-f1 13s-f
1 13s-f
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Day 7 examples u6w14
Day 7 examples u6w14Day 7 examples u6w14
Day 7 examples u6w14
 
2D arrays
2D arrays2D arrays
2D arrays
 
How to graph Functions
How to graph FunctionsHow to graph Functions
How to graph Functions
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
11 graphs of first degree functions x
11 graphs of first degree functions x11 graphs of first degree functions x
11 graphs of first degree functions x
 

Similar to Python PCEP Multidemensional Arrays

Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
Maulen Bale
 

Similar to Python PCEP Multidemensional Arrays (20)

Master the arrays and algorithms using Algotutor
Master the arrays and algorithms using AlgotutorMaster the arrays and algorithms using Algotutor
Master the arrays and algorithms using Algotutor
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
 
Data structures KTU chapter2.PPT
Data structures KTU chapter2.PPTData structures KTU chapter2.PPT
Data structures KTU chapter2.PPT
 
Python data structures
Python data structuresPython data structures
Python data structures
 
Chapter2
Chapter2Chapter2
Chapter2
 
ch07-arrays.ppt
ch07-arrays.pptch07-arrays.ppt
ch07-arrays.ppt
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
 
Lesson 18-20.pptx
Lesson 18-20.pptxLesson 18-20.pptx
Lesson 18-20.pptx
 
Array
ArrayArray
Array
 
Arrays
ArraysArrays
Arrays
 
Killing The Unit test talk
Killing The Unit test talkKilling The Unit test talk
Killing The Unit test talk
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
Merge sort
Merge sortMerge sort
Merge sort
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 

More from IHTMINSTITUTE

More from IHTMINSTITUTE (19)

Python PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesPython PCEP Tuples and Dictionaries
Python PCEP Tuples and Dictionaries
 
Python PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesPython PCEP Tuples and Dictionaries
Python PCEP Tuples and Dictionaries
 
Python PCEP Creating Simple Functions
Python PCEP Creating Simple FunctionsPython PCEP Creating Simple Functions
Python PCEP Creating Simple Functions
 
Python PCEP Functions And Scopes
Python PCEP Functions And ScopesPython PCEP Functions And Scopes
Python PCEP Functions And Scopes
 
Python PCEP Function Parameters
Python PCEP Function ParametersPython PCEP Function Parameters
Python PCEP Function Parameters
 
Python PCEP Functions
Python PCEP FunctionsPython PCEP Functions
Python PCEP Functions
 
Python PCEP Operations On Lists
Python PCEP Operations On ListsPython PCEP Operations On Lists
Python PCEP Operations On Lists
 
Python PCEP Sorting Simple Lists
Python PCEP Sorting Simple ListsPython PCEP Sorting Simple Lists
Python PCEP Sorting Simple Lists
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of Data
 
Python PCEP Logic Bit Operations
Python PCEP Logic Bit OperationsPython PCEP Logic Bit Operations
Python PCEP Logic Bit Operations
 
Python PCEP Loops
Python PCEP LoopsPython PCEP Loops
Python PCEP Loops
 
Python PCEP Comparison Operators And Conditional Execution
Python PCEP Comparison Operators And Conditional ExecutionPython PCEP Comparison Operators And Conditional Execution
Python PCEP Comparison Operators And Conditional Execution
 
Python PCEP How To Talk To Computer
Python PCEP How To Talk To ComputerPython PCEP How To Talk To Computer
Python PCEP How To Talk To Computer
 
Python PCEP Variables
Python PCEP VariablesPython PCEP Variables
Python PCEP Variables
 
Python PCEP Operators
Python PCEP OperatorsPython PCEP Operators
Python PCEP Operators
 
Python PCEP Literals
Python PCEP LiteralsPython PCEP Literals
Python PCEP Literals
 
IHTM Python PCEP Hello World
IHTM Python PCEP Hello WorldIHTM Python PCEP Hello World
IHTM Python PCEP Hello World
 
IHTM Python PCEP Introduction to Python
IHTM Python PCEP Introduction to PythonIHTM Python PCEP Introduction to Python
IHTM Python PCEP Introduction to Python
 
Python PCEP Welcome Opening
Python PCEP Welcome OpeningPython PCEP Welcome Opening
Python PCEP Welcome Opening
 

Recently uploaded

在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 

Recently uploaded (20)

Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
 
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
 

Python PCEP Multidemensional Arrays

  • 1. Module 2 Data Collections – Lists, Tuples, and Dictionaries Multidimensional arrays
  • 2. Module 2 Multidimensional arrays Lists in lists row = [] for i in range(8): row.append(WHITE_PAWN) row = [WHITE_PAWN for i in range(8)] squares = [x ** 2 for x in range(10)] #output [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] twos = [2 ** i for i in range(8)] #output [1, 2, 4, 8, 16, 32, 64, 128] squares = [x ** 2 for x in range(10)] odds = [x for x in squares if x % 2 != 0 ] print(odds) #output [1, 9, 25, 49, 81]
  • 3. Module 2 Multidimensional arrays Two-dimensional arrays board = [] for i in range(8): row = [EMPTY for i in range(8)] board.append(row) EMPTY = "-" ROOK = "ROOK" board = [] for i in range(8): row = [EMPTY for i in range(8)] board.append(row) board[0][0] = ROOK board[0][7] = ROOK board[7][0] = ROOK board[7][7] = ROOK print(board) board = [[EMPTY for i in range(8)] for j in range(8)]
  • 4. Module 2 Multidimensional arrays Multidimensional nature of lists two coordinates a vertical one (row number) a horizontal one (column number) temps = [[0.0 for h in range(24)] for d in range(31)] # The matrix is magically updated here. total = 0.0 for day in temps: total += day[11] average = total / 31 print("Average temperature at noon:", average) The monthly average noon temperature
  • 5. Module 2 Multidimensional arrays Multidimensional nature of lists temps = [[0.0 for h in range(24)] for d in range(31)] # The matrix is magically updated here. highest = -100.0 for day in temps: for temp in day: if temp > highest: highest = temp print("The highest temperature was:", highest) The highest temperature
  • 6. Module 2 Multidimensional arrays Multidimensional nature of lists temps = [[0.0 for h in range(24)] for d in range(31)] # The matrix is magically updated here. hot_days = 0 for day in temps: if day[11] > 20.0: hot_days += 1 print(hot_days, "days were hot.") The days when the temperature at noon was at least 20 ℃
  • 7. Module 2 Multidimensional arrays Three-dimensional arrays • three buildings • 15 floors each • 20 rooms on each floor the type of the array's elements(True/False) calm analysis of the situation rooms = [[[False for r in range(20)] for f in range(15)] for t in range(3)] In the second building, on the tenth floor, room 14: rooms[1][9][13] = True
  • 8. Module 2 Multidimensional arrays Key takeaways 1 [expression for element in list if conditional] # A four-column/four-row table - a two dimensional array (4x4) table = [[":(", ":)", ":(", ":)"], [":)", ":(", ":)", ":)"], [":(", ":)", ":)", ":("], [":)", ":)", ":)", ":("]] print(table) print(table[0][0]) # outputs: ':(' print(table[0][3]) # outputs: ':)' list comprehension use nested lists to create matrices
  • 9. Module 2 Multidimensional arrays Key takeaways 2 # Cube - a three-dimensional array (3x3x3) cube = [[[':(', 'x', 'x'], [':)', 'x', 'x'], [':(', 'x', 'x']], [[':)', 'x', 'x'], [':(', 'x', 'x'], [':)', 'x', 'x']], [[':(', 'x', 'x'], [':)', 'x', 'x'], [':)', 'x', 'x']]] print(cube) print(cube[0][0][0]) # outputs: ':(' print(cube[2][2][0]) # outputs: ':)' create n-dimensional lists
  • 10. Congratulations! You have completed Module 2 Well done! You've reached the end of Module 2 and completed a major milestone in your Python programming education.