Module 7 - Part I: 1D Arrays and Lots of Brackets
Module 7 - Part I: 1D Arrays and Lots of Brackets
OR
2) Create and initialize the array in one line. This is helpful when
we already know those value (e.g. days of the week, etc.).
Creation is different. Must include the typecode (‘i’ in the line below).
myArray = array('i',[10, 20, 30, 40, 50])
Typecode Value
b Represents signed integer of size 1 byte/td>
B Represents unsigned integer of size 1 byte
c Represents character of size 1 byte
i Represents signed integer of size 2 bytes
I Represents unsigned integer of size 2 bytes
f Represents floating point of size 4 bytes
d Represents floating point of size 8 byte
4/10/2019 CSE 1321 3
3. Accessing Information
• Copy information out of a particular slot
• Example:
#Modifying
myArray[3] = 42
print(myArray[3])
42 17 42 -8 4 -8
Finding the Minimum using a
Function
def function(*args):
temp = myArray[0]
for x in myArray:
if (x < temp):
temp = x
print(temp)
#add colors
colors.append('purple')
colors.append('pink')
colors.append('green')
#remove a color
colors.remove('green')
#output list
for x in range(len(colors)):
print (colors[x])