Recipe 16.7. Merging and Splitting TokensRecipe 16.8. Checking Whether a String Has Balanced ParenthesesRecipe 16.9. Simulating Enumerations in PythonRecipe 16.10. Referring to a List Comprehension While Building ItRecipe 16.11. Automating the py2exe Compilation of Scripts into Windows ExecutablesRecipe 16.12. Binding Main Script and Modules into One Executable on UnixChapter 17. Extending and EmbeddingIntroductionRecipe 17.1. Implementing a Simple Extension TypeRecipe 17.2. Implementing a Simple Extension Type with PyrexRecipe 17.3. Exposing a C++ Library to PythonRecipe 17.4. Calling Functions from a Windows DLLRecipe 17.5. Using SWIG-Generated Modules in a Multithreaded EnvironmentRecipe 17.6. Translating a Python Sequence into a C Array with the PySequence_Fast ProtocolRecipe 17.7. Accessing a Python Sequence Item-by-Item with the Iterator ProtocolRecipe 17.8. Returning None from a Python-Callable C FunctionRecipe 17.9. Debugging Dynamically Loaded C Extensions with gdbRecipe 17.10. Debugging Memory ProblemsChapter 18. AlgorithmsIntroductionRecipe 18.1. Removing Duplicates from a SequenceRecipe 18.2. Removing Duplicates from a Sequence While Maintaining Sequence OrderRecipe 18.3. Generating Random Samples with ReplacementRecipe 18.4. Generating Random Samples Without ReplacementRecipe 18.5. Memoizing (Caching) the Return Values of FunctionsRecipe 18.6. Implementing a FIFO ContainerRecipe 18.7. Caching Objects with a FIFO Pruning StrategyRecipe 18.8. Implementing a Bag (Multiset) Collection TypeRecipe 18.9. Simulating the Ternary Operator in PythonRecipe 18.10. Computing Prime NumbersRecipe 18.11. Formatting Integers as Binary StringsRecipe 18.12. Formatting Integers as Strings in Arbitrary BasesRecipe 18.13. Converting Numbers to Rationals via Farey FractionsRecipe 18.14. Doing Arithmetic with Error PropagationRecipe 18.15. Summing Numbers with Maximal AccuracyRecipe 18.16. Simulating Floating PointRecipe 18.17. Computing the Convex Hulls and Diameters of 2D Point SetsChapter 19. Iterators and GeneratorsIntroductionRecipe 19.1. Writing a range-like Function with Float IncrementsRecipe 19.2. Building a List from Any IterableRecipe 19.3. Generating the Fibonacci SequenceRecipe 19.4. Unpacking a Few Items in a Multiple AssignmentRecipe 19.5. Automatically Unpacking the Needed Number of ItemsRecipe 19.6. Dividing an Iterable into n Slices of Stride nRecipe 19.7. Looping on a Sequence by Overlapping WindowsRecipe 19.8. Looping Through Multiple Iterables in ParallelRecipe 19.9. Looping Through the Cross-Product of Multiple IterablesRecipe 19.10. Reading a Text File by ParagraphsRecipe 19.11. Reading Lines with Continuation CharactersRecipe 19.12. Iterating on a Stream of Data Blocks as a Stream of LinesRecipe 19.13. Fetching Large Record Sets from a Database with a GeneratorRecipe 19.14. Merging Sorted SequencesRecipe 19.15. Generating Permutations, Combinations, and SelectionsRecipe 19.16. Generating the Partitions of an IntegerRecipe 19.17. Duplicating an IteratorRecipe 19.18. Looking Ahead into an IteratorRecipe 19.19. Simplifying Queue-Consumer ThreadsRecipe 19.20. Running an Iterator in Another ThreadRecipe 19.21. Computing a Summary Report with itertools.groupbyChapter 20. Descriptors, Decorators,and MetaclassesIntroductionRecipe 20.1. Getting Fresh Default Values at Each Function CallRecipe 20.2. Coding Properties as Nested FunctionsRecipe 20.3. Aliasing Attribute ValuesRecipe 20.4. Caching Attribute ValuesRecipe 20.5. Using One Method as Accessorfor Multiple AttributesRecipe 20.6. Adding Functionality to a Class by Wrapping a MethodRecipe 20.7. Adding Functionality to a Class by Enriching All MethodsRecipe 20.8. Adding a Method to a Class Instance at RuntimeRecipe 20.9. Checking Whether Interfaces Are ImplementedRecipe 20.10. Using _ _new_ _ and _ _init_ _ Appropriately in Custom MetaclassesRecipe 20.11. Allowing Chaining of Mutating List MethodsRecipe 20.12. Using Cooperative Super calls with Terser SyntaxRecipe 20.13. Initializing Instance Attributes Without Using _ _init_ _Recipe 20.14. Automatic Initialization of Instance AttributesRecipe 20.15. Upgrading Class Instances Automatically on reloadRecipe 20.16. Binding Constants at Compile TimeRecipe 20.17. Solving Metaclass ConflictsColophon