Python 3D Academyবাংলা

Standard Library Power Tools in Python

Chapter 30: Standard Library Power Tools

4 short lessons, with 3D animations, quizzes and coding tasks.

The lessons

  1. collections: Counter, defaultdict, deque and namedtuple

    The collections module has ready-made containers for everyday jobs: Counter counts, defaultdict fills in missing keys, deque adds and removes fast at both ends, and namedtuple names a tuple's fields.

  2. itertools: counting, chaining and combining

    itertools makes the sequences you'd otherwise build with nested loops: every combo (product), every unordered group (combinations), every ordering (permutations), and endless counters (count).

  3. heapq: always the smallest first

    A heap is a list arranged so the smallest item is always at index 0, and heapq.heappush/heappop add and remove items while keeping that true.

  4. bisect and functools: find the spot, pre-fill, fold

    bisect finds where a value belongs in a sorted list by halving the search each step, and functools adds tools for functions: partial pre-fills arguments and reduce folds a list into one value.