Introduction Recipe 4.1. Copying an Object Recipe 4.2. Constructing Lists with List Comprehensions Recipe 4.3. Returning an Element of a List If It Exists Recipe 4.4. Looping over Items and Their Indices in a Sequence Recipe 4.5. Creating Lists of Lists Without Sharing References Recipe 4.6. Flattening a Nested Sequence Recipe 4.7. Removing or Reordering Columnsin a List of Rows Recipe 4.8. Transposing Two-Dimensional Arrays Recipe 4.9. Getting a Value from a Dictionary Recipe 4.10. Adding an Entry to a Dictionary Recipe 4.11. Building a Dictionary Without Excessive Quoting Recipe 4.12. Building a Dict from a List of Alternating Keys and Values Recipe 4.13. Extracting a Subset of a Dictionary Recipe 4.14. Inverting a Dictionary Recipe 4.15. Associating Multiple Values with Each Key in a Dictionary Recipe 4.16. Using a Dictionary to Dispatch Methods or Functions Recipe 4.17. Finding Unions and Intersections of Dictionaries Recipe 4.18. Collecting a Bunch of Named Items Recipe 4.19. Assigning and Testing with One Statement Recipe 4.20. Using printf in Python Recipe 4.21. Randomly Picking Items with Given Probabilities Recipe 4.22. Handling Exceptions Within an Expression Recipe 4.23. Ensuring a Name Is Defined in a Given Module |