Class Notes (834,037)
Canada (508,290)
CSC108H1 (113)
Lecture

october 14 notes

3 Pages
112 Views
Unlock Document

Department
Computer Science
Course
CSC108H1
Professor
Michelle Craig
Semester
Fall

Description
 Lists >>> measurement1 = 43.43 >>> instructors = [„michelle‟, „dan‟, „diane‟, >>> measurement2 = 109.34 „andrew‟, „giovanna‟] >>> measurement3 = 123.34 >>> type(instructors) >>> measurements = [43.43‟, 109.34, 123.34] >>> type(measurements) >>> type (instructors[2]) >>> measurements[0] >>> student = ['John Reed', 'Trinity College', 43.34 987632345, 3.45] >>> measurements[1] >>> type(student) 109.34 >>> measurements[2] >>> type (student[0]) 123.43 >>> measurements[-1] >>> type (student[2]) 123.43 >>> measurements[5] >>> type (student[-1]) o Mutability >>> id(instructors) 546312 >>> instructors[2] = „jen‟ #mutable >>> instructors [„michelle‟, „dan‟, „jen‟, „andrew‟, „giovanna‟] >>> id(instructors) 5464312 >>> s = “can‟t do this” >>> s[2] = „x‟ # strings immutable >>> instructors.append(„diane‟) #changes the list, does not create a new one >>> instructors [„michelle‟, „dan‟, „jen‟, „andrew‟, „giovanna‟, „diane‟] >>> instructors.append(65.43) >>> instructors [„michelle‟, „dan‟, „jen‟, „andrew‟, „giovanna‟, „diane‟, 65.43] >>> id(instructors) 5464312 >>> result = instructors.append(„xxx‟) print result None o Lists and built in functions >>> len(instructors) 8 #number of strings in the list >>> measurements [43.34, 109.34, 123.43] >>> max(measurements) 123.43 >>> min(instructors) 43.34 >>> max(instructors) „xxx‟ >>> instructors ['michelle', 'dan', 'jen', 'andrew', 'giovanna', 'diane', 65.43, 'xxx'] >>> min(instructors) 65.43 >>> instructors[-2] = 'paul' >>> instructors ['michelle', 'dan', 'jen', 'andrew', 'giovanna', 'diane', 'paul', 'xxx'] >>> min(instructors) 'andrew' >>> max(instructors, measurements) #max of 2 lists return list w/ max first value ['michelle', 'dan', 'jen', 'andrew', 'giovanna', 'diane', 'paul', 'xxx'] >>> sum(measurements) 276.11 >>> sum(instructors) o Some list methods >>> L = [„a‟, „b‟, „c‟, „d‟] >>> L.append(„e‟) [„a‟, „b‟, „c‟, „d‟, „e‟] >>> L.insert(2, „new‟) >>> L [„a‟, „b‟, „new‟, „c‟, „d‟] >>> L.insert(len(L), „fun‟] >>> L [„a‟, „b‟, „new‟, „c‟, „d‟, „fun‟] >>> L.insert(-1, „wow‟) [„a‟, „b‟, „new‟, „c‟, „d‟, „wow‟, „fun‟] >>> L.insert(999, „www‟) #just a higher number, even out of index [„a‟, „b‟
More Less

Related notes for CSC108H1

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit