Exam 2 Review
Study Topics
This is just a list of topics to help guide your studying. The list is not in order of importance nor should it be considered a complete list of all topics you should know.
-
Regular expressions
- RE syntax
-
re
module functions - Applications
-
Data structures
- Nesting data structures
- Markov chains
- Sets
- Graphs
- Set operations
-
Graph concepts
- Nodes, edges
- Directedness
- Graph picture vs. Python representation
Sample problems
-
Define a function
string_replace(text, old, new)
that returns a new string that is like the given text string, except that each occurrence of the old string is replaced by the new one.An an Orwellian example,
string_replace("COMP 200 is great! Python is even greater!", "great", "plusgood")
should return"COMP 200 is plusgood! Python is even plusgooder!"
.Alas, CodeSkulptor doesn't implement any of the standard Python functions that do such string replacement. Instead, you should implement this in terms of
re.split
. -
Write a function called
num_nodes
, that, given a graph, returns the number of nodes in the graph. -
Write a function called
num_out_nodes
that, given a graph, returns the number of nodes that have an edge leading out of that node. -
Briefly explain why in Python you cannot make a set of lists.
See also the problems on last year's exam 2.