Contents
Preface
Acknowledgments
1 Getting Started
2 Introduction to Python
2.1 The Basic Elements of Python
2.2 Branching Programs
2.3 Strings and Input
2.4 Iteration
3 Some Simple Numerical Programs
3.1 Exhaustive Enumeration
3.2 For Loops
3.3 Approximate Solutions and Bisection Search
3.4 A Few Words About Using Floats
3.5 Newton-Raphson
4 Functions, Scoping, and Abstraction
4.1 Functions and Scoping
4.2 Specifications
4.3 Recursion
4.4 Global Variables
4.5 Modules
4.6 Files
5 Structured Types, Mutability, and Higher-Order Functions
5.1 Tuples
5.2 Lists and Mutability
5.3 Functions as Objects
5.4 Strings, Tuples, and Lists
5.5 Dictionaries
6 Testing and Debugging
6.1 Testing
6.2 Debugging
7 Exceptions and Assertions
7.1 Handling Exceptions
7.2 Exceptions as a Control Flow Mechanism
7.3 Assertions
8 Classes and Object-Oriented Programming
8.1 Abstract Data Types and Classes
8.2 Inheritance
8.3 Encapsulation and Information Hiding
8.4 Mortgages, an Extended Example
9 A Simplistic Introduction to Algorithmic Complexity
9.1 Thinking About Computational Complexity
9.2 Asymptotic Notation
9.3 Some Important Complexity Classes
10 Some Simple Algorithms and Data Structures
10.1 Search Algorithms
10.2 Sorting Algorithms
10.3 Hash Tables
11 Plotting and More About Classes
11.1 Plotting Using PyLab
11.2 Plotting Mortgages, an Extended Example
12 Stochastic Programs, Probability, and Statistics
12.1 Stochastic Programs
12.2 Inferential Statistics and Simulation
12.3 Distributions
12.4 How Often Does the Better Team Win?
12.5 Hashing and Collisions
13 Random Walks and More About Data Visualization
13.1 The Drunkard’s Walk
13.2 Biased Random Walks
13.3 Treacherous Fields
14 Monte Carlo Simulation
14.1 Pascal’s Problem
14.2 Pass or Don’t Pass?
14.3 Using Table Lookup to Improve Performance
14.4 Finding π
14.5 Some Closing Remarks About Simulation Models
15 Understanding Experimental Data
15.1 The Behavior of Springs
15.2 The Behavior of Projectiles
15.3 Fitting Exponentially Distributed Data
15.4 When Theory Is Missing
16 Lies, Damned Lies, and Statistics
16.1 Garbage In Garbage Out (GIGO)
16.2 Pictures Can Be Deceiving
16.3 Cum Hoc Ergo Propter Hoc
16.4 Statistical Measures Don’t Tell the Whole Story
16.5 Sampling Bias
16.6 Context Matters
16.7 Beware of Extrapolation
16.8 The Texas Sharpshooter Fallacy
16.9 Percentages Can Confuse
16.10 Just Beware
17 Knapsack and Graph Optimization Problems
17.1 Knapsack Problems
17.2 Graph Optimization Problems
18 Dynamic Programming
18.1 Fibonacci Sequences, Revisited
18.2 Dynamic Programming and the 0/1 Knapsack Problem
18.3 Dynamic Programming and Divide-and-Conquer
19 A Quick Look at Machine Learning
19.1 Feature Vectors
19.2 Distance Metrics
19.3 Clustering
19.4 Types Example and Cluster
19.5 K-means Clustering
19.6 A Contrived Example
19.7 A Less Contrived Example
19.8 Wrapping Up
Python 2.7 Quick Reference
Index
Uploaded by [StormRG]