notes05a

Append5 3 lextendl1 linsert 3 149 l3pop

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 3] Examples: L [4, 5, 7, “c”,  ­3] Input L1=L L1=L[:] L3=L[:2] L[3] L1[3] len(L) L.append(47) L.append([ ­5, 3]) L.extend(L1) L.insert( 3, 14.9) L3.pop() L1.pop() L1.pop(2) Results L [4, 5, 7, “c”,  ­3] L1 L [4, 5, 7, “c”,  ­3] L1 [4, 5, 7, “c”,  ­3] L3 [4, 5] “c” “c” 5 [4, 5, 7, “c”,  ­3, 47] 4, 5, 7, “c”,  ­3, 47,  ­5, 3] [4, 5, 7, “c”,  ­3, 47,  ­5, 3, 4, 5, 7, 1,  3] [4, 5, 7 , 14.9, “c”,  ­3, 47,  ­5, 3] [4] [4, 5, 7, 1] [4, 5, 1,  ­3] Note *(L1 is a list) (note: L1=[4, 5, 7, 1,  ­3] ) (note: L1=[4, 5, 7, 1,  ­3] ) bc2chow Arrays Int a[100] • Differences between arrays and lists (python) 1) Length of the arrays is immutable – you cannot expand the arrays 2) Each element in the array is of the same type • Removing item from end of list is cheaper than removing from beginning of the list • # of slots … 2x • If append (no more slots) then slots become 2x+1 Matrix ADT • Matrix collection of scalar values arranged in rows and columns as a fixed sized rectangular grid Matrix Implementation How should we implement the matrix ADT? 1) 2 Dimensional array 2 indices 2 4 7 5 3 9  ­1 4 8 7 2) List within list 3) Dictionaries (hard) 5 3...
View Full Document

Ask a homework question - tutors are online