Chapter 4. Python Shortcuts
- IntroductionRecipe 4.1.
Copying an ObjectRecipe 4.2.
Constructing Lists with List ComprehensionsRecipe 4.3.
Returning an Element of a List If It ExistsRecipe 4.4.
Looping over Items and Their Indices in a SequenceRecipe 4.5.
Creating Lists of Lists Without Sharing ReferencesRecipe 4.6.
Flattening a Nested SequenceRecipe 4.7.
Removing or Reordering Columnsin a List of RowsRecipe 4.8.
Transposing Two-Dimensional ArraysRecipe 4.9.
Getting a Value from a DictionaryRecipe 4.10.
Adding an Entry to a DictionaryRecipe 4.11.
Building a Dictionary Without Excessive QuotingRecipe 4.12.
Building a Dict from a List of Alternating Keys and ValuesRecipe 4.13.
Extracting a Subset of a DictionaryRecipe 4.14.
Inverting a DictionaryRecipe 4.15.
Associating Multiple Values with Each Key in a DictionaryRecipe 4.16.
Using a Dictionary to Dispatch Methods or FunctionsRecipe 4.17.
Finding Unions and Intersections of DictionariesRecipe 4.18.
Collecting a Bunch of Named ItemsRecipe 4.19.
Assigning and Testing with One StatementRecipe 4.20.
Using printf in PythonRecipe 4.21.
Randomly Picking Items with Given ProbabilitiesRecipe 4.22.
Handling Exceptions Within an ExpressionRecipe 4.23.
Ensuring a Name Is Defined in a Given Module