Data Structures Arrays / Stacks, Queues and Linked Lists

## 12/11 Nov Class Activity

• 1
Create Python code to set up a 1 dimensional array of items of your choice.
• 2
Iterate thru the array and print out each array element.
• 3
• 4
Iterate thru the 2D arrays printing out all elements in row 0 followed by all elements in row 1
• 5
Write your solution to step 4 in IB Pseudo CODE
• 6
Create blog page and copy the python code and the pseudo code to that page and post solution to google classroom

## 1 Dimensional Arrays

An array is a data structure that lets you hold list of like items ( rather than use multiple variables)

Example if we wish to store a list of car manufactures we could hold as 1 dimensional array. Remember the first element starts at 0

car_array = ["Volvo","BMW","Honda"]

In python we can iterate thru a list in 2 ways

car_array= ["bmw","honda"]

for i in range(len(car_array)):

print(car_array[i])

car_array= ["bmw","honda"]

for element in car_array:

print(element)

## 2 Dimensional Arrays

In real-world Often tasks have to store rectangular data table( board games for example). Such tables are called matrices or two-dimensional arrays. In Python any table can be represented as a list of lists (a list, where each element is in turn a list).

When we process 2D arrays we use a loop with a loop : Write some code to print out each element in car_array

car_array= [["bmw","honda"],["red","blue"]]

# row 0  =  bmw, honda

# row 1 = red, blue

print(car_array)

print(car_array)

a = [["bmw","honda"],["red","blue"]]

for  i in range (len(a)):

for j in range (len(a[i])):

#print each element in the array

print(car_array)

## 12/11 Nov Class Activity

• 1
Create Python code to set up a 1 dimensional array of items of your choice.
• 2
Iterate thru the array and print out each array element.
• 3
• 4
Iterate thru the 2D arrays printing out all elements in row 0 followed by all elements in row 1
• 5
Write your solution to step 4 in IB Pseudo CODE
• 6
Create blog page and copy the python code and the pseudo code to that page and post solution to google classroom

## 1 Dimensional Arrays

An array is a data structure that lets you hold list of like items ( rather than use multiple variables)

Example if we wish to store a list of car manufactures we could hold as 1 dimensional array. Remember the first element starts at 0

car_array = ["Volvo","BMW","Honda"]

In python we can iterate thru a list in 2 ways

car_array= ["bmw","honda"]

for i in range(len(car_array)):

print(car_array[i])

car_array= ["bmw","honda"]

for element in car_array:

print(element)

## 2 Dimensional Arrays

In real-world Often tasks have to store rectangular data table( board games for example). Such tables are called matrices or two-dimensional arrays. In Python any table can be represented as a list of lists (a list, where each element is in turn a list).

When we process 2D arrays we use a loop with a loop : Write some code to print out each element in car_array

car_array= [["bmw","honda"],["red","blue"]]

# row 0  =  bmw, honda

# row 1 = red, blue

print(car_array)

print(car_array)

a = [["bmw","honda"],["red","blue"]]

for  i in range (len(a)):

for j in range (len(a[i])):

#print each element in the array

print(car_array)

## 12/11 Nov Class Activity

• 1
Create Python code to set up a 1 dimensional array of items of your choice.
• 2
Iterate thru the array and print out each array element.
• 3
• 4
Iterate thru the 2D arrays printing out all elements in row 0 followed by all elements in row 1
• 5
Write your solution to step 4 in IB Pseudo CODE
• 6
Create blog page and copy the python code and the pseudo code to that page and post solution to google classroom

## 1 Dimensional Arrays

An array is a data structure that lets you hold list of like items ( rather than use multiple variables)

Example if we wish to store a list of car manufactures we could hold as 1 dimensional array. Remember the first element starts at 0

car_array = ["Volvo","BMW","Honda"]

In python we can iterate thru a list in 2 ways

car_array= ["bmw","honda"]

for i in range(len(car_array)):

print(car_array[i])

car_array= ["bmw","honda"]

for element in car_array:

print(element)

## 2 Dimensional Arrays

In real-world Often tasks have to store rectangular data table( board games for example). Such tables are called matrices or two-dimensional arrays. In Python any table can be represented as a list of lists (a list, where each element is in turn a list).

When we process 2D arrays we use a loop with a loop : Write some code to print out each element in car_array

car_array= [["bmw","honda"],["red","blue"]]

# row 0  =  bmw, honda

# row 1 = red, blue

print(car_array)

print(car_array)

a = [["bmw","honda"],["red","blue"]]

for  i in range (len(a)):

for j in range (len(a[i])):

#print each element in the array

print(car_array)

## 12/11 Nov Class Activity

• 1
Create Python code to set up a 1 dimensional array of items of your choice.
• 2
Iterate thru the array and print out each array element.
• 3
• 4
Iterate thru the 2D arrays printing out all elements in row 0 followed by all elements in row 1
• 5
Write your solution to step 4 in IB Pseudo CODE
• 6
Create blog page and copy the python code and the pseudo code to that page and post solution to google classroom

## 1 Dimensional Arrays

An array is a data structure that lets you hold list of like items ( rather than use multiple variables)

Example if we wish to store a list of car manufactures we could hold as 1 dimensional array. Remember the first element starts at 0

car_array = ["Volvo","BMW","Honda"]

In python we can iterate thru a list in 2 ways

car_array= ["bmw","honda"]

for i in range(len(car_array)):

print(car_array[i])

car_array= ["bmw","honda"]

for element in car_array:

print(element)

## 2 Dimensional Arrays

In real-world Often tasks have to store rectangular data table( board games for example). Such tables are called matrices or two-dimensional arrays. In Python any table can be represented as a list of lists (a list, where each element is in turn a list).

When we process 2D arrays we use a loop with a loop : Write some code to print out each element in car_array

car_array= [["bmw","honda"],["red","blue"]]

# row 0  =  bmw, honda

# row 1 = red, blue

print(car_array)

print(car_array)

a = [["bmw","honda"],["red","blue"]]

for  i in range (len(a)):

for j in range (len(a[i])):

#print each element in the array

print(car_array)