Please enable JavaScript.
Coggle requires JavaScript to display documents.
arrays and lists, 2D arrays - Coggle Diagram
arrays and lists
-
-
-
-
-
-
-
tuple
static, immutable, can store several different data types
-
-
-
list
dynamic, mutable, can store several different data types
index positions
rainbow=[“red”, “orange”, “yellow”, “green”, “blue”, “indigo”, “violet”]
red = index pos. 0
orange = index pos. 1
yellow = index pos. 2
green = index pos. 3
blue = index pos. 4
indigo = index pos. 5
violet = index pos. 6
-
-
array
static , mutable, can only store items of the same data type
-
-
-
-
-
2D arrays
traversing
Python - 1results = [ ["Dave", 82], ["Fred", 98] ]For index in range (len(results)):
- if results[index] [1] >= 50:
- print("{} {}" .format(results[index] [0], results [index] [1]))
Pseudocode - 1for index = 0 to results.length -1
- if results[index, 1] >= 50 then
- print(results[index, 0] + results[index, 1])
- endif
next index
Python - 2for index in range (len(list)):
for row in list:
Pseudocode - 2for index = 0 to array.length-1
slicing
Pseudocode
cars=[ [“Ford”, “blue”] , [“Renault”, “red”] , [“Vauxhall”, “silver”] ]
print(cars[1,1] )
# Prints red
Python
cars=[ [“Ford”, “blue”] , [“Renault”, “red”] , [“Vauxhall”, “silver”] ]
print(cars[1] [1] )
#Prints red
-
replace values
Pseudocode
cars=[ [“Ford”, “blue”] , [“Renault”, “red”] ]
cars [1,1] = “green”
# replaces red with green
-
-
append values
Python
listName.append([e , f])
# appends a new mini list to the listName 2D list
-
-