This preview shows page 1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-117-118-119-120-121-122-123-124-125-126-127-128-129-130-131-132-234-235-236-237-238-239-240-241-242-243-244-245-246-247-248-249-250 out of 250 pages.
61A Lecture 35Monday, 28th November, 2011Monday, November 28, 2011Last time: sequential data and iterators2Monday, November 28, 2011Last time: sequential data and iteratorsSequences2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so far2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so farLength2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so farLengthElement selection2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so farLengthElement selection•Lists and tuples2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so farLengthElement selection•Lists and tuplesStore all elements up-front2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so farLengthElement selection•Lists and tuplesStore all elements up-frontcan’t deal with huge data2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so farLengthElement selection•Lists and tuplesStore all elements up-frontcan’t deal with huge datacan’t deal with infinite sequences2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so farLengthElement selection•Lists and tuplesStore all elements up-frontcan’t deal with huge datacan’t deal with infinite sequencesIterators2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so farLengthElement selection•Lists and tuplesStore all elements up-frontcan’t deal with huge datacan’t deal with infinite sequencesIteratorsStore how to compute elements2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so farLengthElement selection•Lists and tuplesStore all elements up-frontcan’t deal with huge datacan’t deal with infinite sequencesIteratorsStore how to compute elementsCompute one element at a time2Monday, November 28, 2011Last time: sequential data and iteratorsSequencesThe sequence abstraction so farLengthElement selection•Lists and tuplesStore all elements up-frontcan’t deal with huge datacan’t deal with infinite sequencesIteratorsStore how to compute elementsCompute one element at a timeDelay evaluation2Monday, November 28, 2011Last time: sequential data and iterators3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored“compute_rest” is stored3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored“compute_rest” is storedcalculate “rest” on demand3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored“compute_rest” is storedcalculate “rest” on demandNative python iterator interface3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored“compute_rest” is storedcalculate “rest” on demandNative python iterator interface__iter__()3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored“compute_rest” is storedcalculate “rest” on demandNative python iterator interface__iter__()__next__()3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored“compute_rest” is storedcalculate “rest” on demandNative python iterator interface__iter__()__next__()for-loops rely on these methods3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored“compute_rest” is storedcalculate “rest” on demandNative python iterator interface__iter__()__next__()for-loops rely on these methodsGenerator functions3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored“compute_rest” is storedcalculate “rest” on demandNative python iterator interface__iter__()__next__()for-loops rely on these methodsGenerator functionsFunctions that use yield to output values3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored“compute_rest” is storedcalculate “rest” on demandNative python iterator interface__iter__()__next__()for-loops rely on these methodsGenerator functionsFunctions that use yield to output valuesCreates a generator object3Monday, November 28, 2011Last time: sequential data and iteratorsStreams -- a unit of delayed evaluation. 2 elements, first and rest.“first” is stored“compute_rest” is storedcalculate “rest” on demandNative python iterator interface__iter__()__next__()for-loops rely on these methodsGenerator functionsFunctions that use yield to output valuesCreates a generator object__iter__() and __next__() automatically defined3Monday, November 28, 2011Today: modularity, processing pipelines, and coroutinesModularity in programs so farHelper functions a.k.a “subroutines”Coroutines: what are they?Coroutines in pythonTypes of coroutinesMultitasking4Monday, November 28, 2011Modularity so far: helper functions5Monday,
View Full Document