- You are here:
- Home »
- 2 D arrays

**Data Structures Arrays / Stacks, Queues and Linked Lists**

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

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)

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[1][0])

print(car_array[1][1])

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[1][1])

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

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)

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[1][0])

print(car_array[1][1])

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[1][1])

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

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)

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[1][0])

print(car_array[1][1])

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[1][1])

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

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)

*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).

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

# row 0 = bmw, honda

# row 1 = red, blue

print(car_array[1][0])

print(car_array[1][1])

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[1][1])

Arrays VS

Linked Lists

Fast Access

Linear / Sequential Access