Errata

Page 85 (Spotted by Federico Arismendi - thanks!) 

The line

['harry', 'ian', 'lucy', 'mike', 'sue']

should be 

['sue', 'ian', 'mike', 'lucy', 'harry']

A copy and paste error.

 

Page 98

If you can type a Unicode character then you can use it within string literals and variable names. Unicode in variable names is limited to code points that are part of a language and so you can use emojis or graphical symbols.

Sh

 

 

ould read

If you can type a Unicode character then you can use it within string literals and variable names. Unicode in variable names is limited to code points that are part of a language and so you cannot use emojis or graphical symbols.

i.e. can should be cannot

Page 102

s = s[:i]+"X"+s[i+1:]

should be 

s = s[:i+1]+"X"+s[i+1:]

the first removes the ith character and the second doesn't

Page 103

The split method can be thought of as the inverse of join:

split(sep.max)

it returns a list of strings separated using the location of the string specified by sep. Note that the sep string is not included in the result and can be multiple characters You can optionally specify a maximum number of elements in the list. The method:

rsplit(sep.max)

does the same job but starts from the end of the string. For example:

Should be

The split method can be thought of as the inverse of join:

split(sep,max)

it returns a list of strings separated using the location of the string specified by sep. Note that the sep string is not included in the result and can be multiple characters You can optionally specify a maximum number of elements in the list. The method:

rsplit(sep,max)

does the same job but starts from the end of the string. For example:

i.e. commas not dots in functions.

Page 105

s = "This parrot is no more"
I = s.find("parrot")
s = s[:i]+"hamster"+s[i+len("parrot"):]

should be

s = "This parrot is no more"
i = s.find("parrot")
s = s[:i]+"hamster"+s[i+len("parrot"):]

i.e. lower case I

 Page 108 

The match object always returns True so it is easy to test if a match occurred:

 should read

The match object always returns True if a match occurred:

 Page 112

remove the extra < from:

print(ex2.search(r"<<div>hello</div><div>world</div>")[0])

i.e.

print(ex2.search(r"<div>hello</div><div>world</div>")[0])

also the paragraph that follows is clearer if the word "final" is removed as there is only one closing div:

That is, the </div> in the regular expression is matched to the final </div> in the string, even though there is an earlier occurrence of the same substring.

Page 125

The first is that the entries in the are fixed in size and small compared to the entries in the data table.

add two missing words

The first is that the entries in the hash table are fixed in size and small compared to the entries in the data table.

i.e. add hash table

 

Page 127

Notice that while you use curly brackets to initialize a list you use square brackets for indexing, as with a list.

change list to dictionary

Notice that while you use curly brackets to initialize a dictionary you use square brackets for indexing, as with a list.

 

 Page 140

missing self in index+=1

class myIterator:
	def __init__(self):
		self.index=0
	def __iter__(self):
		return self
	def __next__(self):
		res = seq[index]
		index+=1
		return res

should read

class myIterator:
	def __init__(self):
		self.index=0
	def __iter__(self):
		return self
	def __next__(self):
		res = seq[index]
		self.index+=1
		return res

 

 Page 177 and page 183

Change 

 

    def appendBreathFirst(self,value):

 to 

 def appendBreadthFirst(self,value):

and

tree = Tree(0)
for i in range(1,14):
    tree.appendBreathFirst(i)

to

tree = Tree(0)
for i in range(1,14):
    tree.appendBreadthFirst(i)

i.e. change breath to breadth - dislexia rules!

Page 178 

change 

This algorithm is also usually implemented as recursion, but we can use a data structure to sort the unfinished nodes to return to later.

to

This algorithm is also usually implemented as recursion, but we can use a data structure to store the unfinished nodes to return to later.

i.e. change stort to store

Page 186

The binary number

101010111100110111101111

 should, of course, be:

1010 1011 1100 1101 1110

 

Page 221

  • Path,anchor 

should be

  • Path.anchor 

i.e. dot not comma