COMP10001 Lecture Notes - Lecture 8: Iter, Iterator, Plaintext

50 views1 pages
CSV = comma
-
separated values
-
Stores tabulated data as plain
-
text, separated by commas
-
import csv
-
-
use csv.reader() to import the data into a list of lists
-
CSV files:
iterator = object that keeps track of the traversal of a container
-
an iterable object will return an iterator object when passed to the built
-
in Python function
iter()
-
__next__ method returns the next thing in the iteration and updates their state/memory of
where they are up to
-
StopIteration exceptions is raised when the container is empty
-
iterators are more memory efficient than storing and indexing a whole iterable
-
no random access
"remembers" last item seen
no len()
can be infinite
traverse exactly once (forwards)
characteristics:
-
Iterators:
implements a number of iterator "building blocks"
-
standardises a set of fast, memory efficient tools
-
forms an "iterator algebra"
-
product = cross
-
product of sequences
cycle = repeat items indefinitely
groupby = group items by some criterion
combinations = n choose k
useful functions
-
The itertools module:
break the problem down into smaller sub
-
problems
solve each sub
-
problem the same way as the big problem
recursive function definitions are often used to solve problems in a divide
-
and
-
conquer
manner
-
recursive function calls on smaller inputs
a reachable base case to ensure the calculation halts
generally made up of two parts
-
head recursion = recurse first, then perform some local calculation
-
tail recursion = perform some local calculation, then recurse
-
Recursion:
Week 8
Thursday, 3 May 2018 11:34 AM
Foundations of Computing Page 1
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers