Itemgetter, Sorting, and Debugging/Testing
Winter 2025
1
Adrian Salguero
Announcements
2
Review: Itemgetter and Sorting
Review solutions to the additional practice problems here
3
Situation: Your code does not work!
4
Three classifications of errors
5
Options on how to debug
6
Tips on how to debug
7
Read the error message
Traceback (most recent call last):
File "nx_error.py", line 41, in <module>
print(friends_of_friends(rj, myval))
File "nx_error.py", line 30, in friends_of_friends
f = friends(graph, user)
File "nx_error.py", line 25, in friends
return set(graph.neighbors(user))#
File "/Library/Frameworks/…/graph.py", line 978, in neighbors
return list(self.adj[n])
TypeError: unhashable type: 'list'
List of all exceptions (errors):
http://docs.python.org/3/library/exceptions.html#bltin-exceptions
Two other resources, with more details about a few of the errors:
First function that was called (<module> means the interpreter)
Second function that was called
Last function that was called (this one suffered an error)
The error message:�daunting but useful.�You need to understand:
Common Error Types
9
What's the most important aspect of a program?
10
Correctness
Pros
Cons
11
Correctness
12
Speed
Pros
Cons
13
Style
Pros
Cons
14
Style
15