W8_dictionaries - Two new data types this week! tuples:...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Two new data types this week! tuples : like lists , but safer what's unsafe about lists? - anybody can change them, as we saw earlier tuples are immutable (just like strings) 1 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Tuples t = (1, 2) r = (1,) s = ('a', 'b', 'c') s[0]? s[3]? len(s)? s[0] = 'A'? 2 2
Background image of page 2
Tuples can be used for multiple return values def max_min(L): '''Return the maximum and the minimum value of list L as a tuple, in that order.''' return max(L), min(L) OR: return (max(L), min(L)) # calling the function and naming the return values: (biggest, smallest) = max_min(L) OR: biggest, smallest = max_min(L) 3 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Dictionaries CO2 Emissions by year in North America (thousands of tons of carbon) 1799 1 1800 70 1801 74 1802 79 1902 21563 2002 1733297 How can we represent this in a program? 4 4
Background image of page 4
Dictionaries Carbon emissions - cont'd One obvious choice: lists year = [1799, 1800, 1801, 1802, 1902, 2002] CO2 = [1, 70, 74, 79, 215630, 1733297] The CO2 list at position i represents the emission for the year at position i in the year list 5 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

W8_dictionaries - Two new data types this week! tuples:...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online