Class Notes (839,104)
Canada (511,191)
CSC108H1 (113)
Lecture

october 28 notes

2 Pages
81 Views

Department
Computer Science
Course Code
CSC108H1
Professor
Michelle Craig

This preview shows 80% of the first page. Sign up to view the full 2 pages of the document.
Description
 A2, Keys and filters case sensitive :Dan: and [‘dan’, [‘a.jpg’, ‘b.jpg’] different o Also differ in type, ie 123 string different from 123 type  Filter not grammatical, :giraffe: and not :Dan: and :Diane: o If “not” precedes key, removes similar images; if only “and” remove the non-common images o If filter exists for a key that doesn’t  “not” everything remains, “and” everything removes  Dictionary >>> names = [„Pauline‟, „Rob‟, „Peter‟] >>> marks = [98, 75, 42] >>> I = names.index(„Rob‟) >>> print i 1 >>> marks[1] # parallel arrays or parallel lists 75 >>> marks[2] 42 >>> dict_marks = {„Pauline‟:98, „Rob”:75, „Peter‟:42} >>> dict_marks[„Peter‟] # call marks based on key not position 42 >>> dict_marks[„Rob‟] 75 >>> dict_marks[„Peter‟] = 62 62 >>> dict_marks {„Rob‟: 75, „Peter‟: 62, „Pauline‟: 98} #no promised order in dictionary, not necessarily alphabetical and by order of input >>> dict_marks[„Mary‟] = 74 # dictionaries mutable >>> dict_marks {„Rob‟: 75, „Peter‟: 62, „Mary‟: 74, „Pauline‟: 98} >>> for item in dict_marks: … print type(item) … print item … Rob Peter Mary Pauline >>> emissions_by_year = {1799: 1, 1800: 70, 1902: 215630, 2002: 1733297} >>> for item in emissions_by_year: … print item … print type(item) 1800 2002 1902 1799 >>> emissions_by_year.keys() [1800, 2002, 1902, 1799] >>> for key in emissions_by_year: … print key, emissions_by_year[key] … 1800 70 2002 1733297 1902 215630 1799 1 >>> keys = emissions_by_year.keys() >>> keys [1800, 2002, 1902, 1799] >>> keys.sort() >>> keys [1799, 1800, 1902, 2002] >>> for year in keys: … print year, emissions_by_year[year] 1799 1 1800 70 1902 215630 2002 1733297 o Keys and values >>> dict_marks {„Rob‟: 75, „Peter‟: 62, „Mary‟: 74, „Pauline‟: 98} >>> dict_marks[„Diane‟] = „profs do not get marks‟ >>> dict_marks # immutable object as keys only, doesn‟t accept mutable {„Rob‟: 75, „Peter‟: 62, “Diane‟: „profs do not get marks‟, „Mary‟: 72, „Pauline‟: 98} >>> dict_marks[99] = [1, 2, 3, 4] >>> dict_marks # immutable & mutable accepted as values {99: [1, 2, 3, 4], „Pauline‟: 98
More Less
Unlock Document

Only 80% of the first page are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

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