Chapter 2
- The most appropriate data structure for each of the following use cases is as follows:
- Mapping items to another set of items (with set being used in the most general sense): dictionaries.
- Accessing, modifying, and appending elements: lists.
- Maintaining a collection of unique elements: sets.
- Keeping track of the minimum/maximum of a set (in the most general sense): heaps.
- Appending and removing elements at the endpoints of a sequence (in the most general sense): deques.
- Fast searching according to some similarity criterion (used by, for example, autocompletion engines): tries.
- Caching is a design where we store expensive results in a temporary location, which can be in memory, on-disk, or a remote location. Memoization is specifically about storing and reusing the results of previous function calls in an application. As such, memoization is a form of caching.
- Comprehensions and generators are optimized under the hood, so they are generally more efficient than explicit...