Preface 1. Data Structures and Algorithms. 1.1. Unpacking a Sequence into Separate Variables 1.2. Unpacking Elements from Iterables of Arbitrary Length 1.3. Keeping the Last N Items 1.4. Finding the Largest or Smallest N Items 1.5. Implementing a Priority Queue 1.6. Mapping Keys to Multiple Values in a Dictionary 1.7. Keeping Dictionaries in Order 1.8. Calculating with Dictionaries 1.9. Finding Commonalities in Two Dictionaries 1.10. Removing Duplicates from a Sequence while Maintaining Order 1.11. Naming a Slice 1.12. Determining the Most Frequently Occurring Items in a Sequence 1.13. Sorting a List of Dictionaries by a Common Key 1.14. Sorting Objects With out Native Comparison Support 1.15. Grouping Records Together Based on a Field 1.16. Filtering Sequence Elements 1.17. Extracting a Subset of a Dictionary 1.18. Mapping Names to Sequence Elements 1.19. Transforming and Reducing Data at the Same Time 1.20. Combining Multiple Mappings into a Single Mapping 2. Strings and Text 2.1. Splitting Strings on Any of Multiple Delimiters 2.2. Matching Text at the Start or End of a String 2.3. Matching Strings Using Shell Wildcard Patterns 2.4. Matching and Searching for Text Patterns 2.5. Searching and Replacing Text 2.6. Searching and Replacing Case-Insensitive Text 2.7. Specifying a Regular Expression for the Shortest Match 2.8. Writing a Regular Expression for Multiline Patterns 2.9. Normalizing Unicode Text to a Standard Representation 2.10. Working with Unicode Characters in Regular Expressions 2.11. Stripping Unwanted Characters from Strings 2.12. Sanitizing and Cleaning Up Text 2.13. Aligning Text Strings 2.14. Combining and Concatenating Strings 2.15. Interpolating Variables in Strings 2.16. Reformatting Text to a Fixed Number of Columns 2.17. Handling HTML and XML Entities in Text 2.18. Tokenizing Text 2.19. Writing a Simple Recursive Descent Parser 2.20. Performing Text Operations on Byte Strings 3. Numbers, Dates, and Times 3.1. Rounding Numerical Values 3.2. Performing Accurate Decimal Calculations 3.3. Formatting Numbers for Output 3.4. Working with Binary, Octal, and Hexadecimal Integers 3.5. Packing and Unpacking Large Integers from Bytes 3.6. Performing Complex-Valued Math 3.7. Working with Infinity and NaNs 3.8. Calculating with Fractions 3.9. Calculating with Large Numerical Arrays 3.10. Performing Matrix and Linear Algebra Calculations 3.11. Picking Things at Random 3.12. Converting Days to Seconds, and Other Basic Time Conversions 3.13. Determining Last Friday's Date 3.14. Finding the Date Range for the Current Month 3.15. Converting Strings into Datetimes 3.16. Manipulating Dates Involving Time Zones 4. lterators and Generators. 4.1. Manually Consuming an Iterator 4.2. Delegating Iteration 4.3. Creating New Iteration Patterns with Generators 4.4. Implementing the Iterator Protocol 4.5. Iterating in Reverse 4.6. Defining Generator Functions with Extra State …… 5. Files and I/O 6. Data Encoding and Processing 7. Functions 8. Classes and Objects 9. Metaprogramming 10. Modulesand Packages 11. Network and Web Programming 12. Concurrency 13. Utility Scripting and System Administration 14. Testing, Debugging, and Exceptions 15. c Extensions