Toggle Navigation
Everything
Blog posts
Pages
Home
About
The Author
The Book
This Website
Book
Chapter 1: Introduction
Chapter 2: The Core Python Language I
Examples
Questions
Problems
Additional Problems
Chapter 3: Simple Plotting with pylab
Examples
Problems
Chapter 4: The core Python language II
Examples
Questions
Problems
Additional Problems
Chapter 5: IPython and IPython Notebook
Examples
Chapter 6: NumPy
Examples
Questions
Problems
Additional Examples
Additional Problems
Chapter 7: Matplotlib
Examples
Questions
Problems
Chapter 8: SciPy
Examples
Questions
Problems
Additional Examples
Additional Problems
Chapter 9: General Scientific Programming
Examples
Questions
Problems
Errata
Book (2nd ed.)
Chapter 1: Introduction
Chapter 2: The Core Python Language I
Examples
Questions
Problems
Additional Problems
Chapter 3: Simple Plots and Charts
Examples
Problems
Chapter 4: The core Python language II
Examples
Questions
Problems
Additional Problems
Chapter 5: IPython and Jupyter Notebook
Examples
Problems
Chapter 6: NumPy
Examples
Questions
Problems
Additional Examples
Additional Problems
Chapter 7: Matplotlib
Examples
Questions
Problems
Chapter 8: SciPy
Examples
Questions
Problems
Additional Examples
Additional Problems
Chapter 9: Data Analysis with pandas
Examples
Problems
Chapter 10: General Scientific Programming
Examples
Questions
Problems
Errata
Additional Notes
Blog
Apps
Contact
Home
Book (2nd ed.)
Chapter 4: The core Python language II
Chapter 4: The core Python language II
Examples
E4.1 Assignment vs. the comparison operator
E4.2 Exception tracebacks
E4.3 String representation of vectors
E4.4 Vector cross product
E4.5 try ... except ... else ... finally
E4.6 A simple dictionary of Roman numerals
E4.7 A simple database of astronomical objects
E4.8 Word lengths in the first line of the Gettysburg Address
E4.9 Mersenne primes
E4.10 The matrix transpose by list comprehension
E4.11 lambda functions
E4.12 Sorting methods
E4.13 Triangular numbers
E4.14 Assignment expressions (the walrus operator)
E4.15 Issuing a usage method
E4.16 Batch renaming of files
E4.17 The Monty Hall problem
E4.18 A simple Python class
E4.19 The random-flight polymer
E4.20 A 2D vector class
E4.21 A simple 2D molecular dynamics simulation
Questions
Q4.1.1 The else block of a try ... except clause
Q4.1.2 The finally block of a try ... except clause
Q4.2.1 Determining if a string is a pangram
Q4.2.2 Removing duplicates from a list
Q4.2.3 Defining set objects
Q4.2.4 frozenset
Q4.2.5 Grouping words by their length using a defaultdict
Q4.3.1 List comprehension and lambda functions
Q4.3.2 Mystery list comprehension
Q4.3.3 Various list comprehensions
Q4.3.4 Sorting a dictionary
Q4.3.5 The "jump the five" cypher
Q4.3.6 Sorting a list containing None
Q4.3.7 Using an assignment expression
Problems
P4.1
P4.1.1 Average air-speed of an unladen African swallow
P4.1.2 String representation of a vector
P4.1.3 Raising an exception on $0^0$
P4.2
P4.2.1 Resistor colour codes
P4.2.2 The most 100 frequent words in Moby Dick
P4.2.3 A reverse polish notation calculator
P4.2.4 A Morse Code generator
P4.2.5 Shark species
P4.3
P4.3.1 Matrix trace
P4.3.2 The ROT-13 cypher
P4.3.3 Rule 30
P4.3.4 IBAN code lengths
P4.3.5 Power sets
P4.3.6 Word analysis
P4.4
P4.4.1 Hailstone sequence generator with a usage message
P4.4.2 The haversine formula
P4.4.3 Creating a set of SVG image files
P4.4.4 Batch renaming of files
P4.5
Monte-Carlo Integration: the Error Function
P4.6
P4.6.1 Modifying the BankAccount class
P4.6.2 Saving a polymer image
P4.6.3 The Yale Bright Star catalog
P4.6.4 A simple class for linear regression
P4.6.5 A one-based list
Additional Problems
The Olympic Heptathlon