Think Python: How to Think Like a Computer Scientist
Counters A Counter is like a set, except that if an element appears more than once, the Counter keeps ...
defaultdict The collections module also provides defaultdict, which is like a dictionary except that if y ...
return d This solution has the drawback that it makes a new list every time, regardless ...
Named Tuples Many simple objects are basically collections of related values. For example, the Point object define ...
Named tuples provide a quick way to define simple classes. The drawback is that simple classes don’t alway ...
Gathering Keyword Args In “Variable-Length Argument Tuples”, we saw how to write a function that gather ...
Glossary conditional expression: An expression that has one of two values, depending on a condition. list comprehe ...
Exercises Exercise 19-1. The following is a function that computes the binomial coefficient recursively: def ...
...
Chapter 20. Debugging When you are debugging, you should distinguish among different kinds of errors in order to ...
Syntax Errors Syntax errors are usually easy to fix once you figure out what they are. Unfortunately, the ...
If nothing works, move on to the next section... ...
I keep making changes and it makes no difference. If the interpreter says there is an error and you don’t ...
Runtime Errors Once your program is syntactically correct, Python can read it and at least start running ...
My program does absolutely nothing. This problem is most common when your file consists of functions ...
My program hangs. If a program stops and seems to be doing nothing, it is “hanging”. Often that means t ...
making a recursive invocation. If not, you need to rethink the algorithm and identify a base case. If ther ...
When I run the program I get an exception. If something goes wrong during runtime, Python prints a messa ...
IndexError: The index you are using to access a list, string, or tuple is greater than its length minus one. ...
I added so many print statements I get inundated with output. One of the problems with using print ...
«
13
14
15
16
17
18
19
20
21
22
»
Free download pdf