hettinger_skill

This skill helps you write idiomatic Python in the Hettinger style, using generators, iterators, and built-ins for clean, efficient code.
  • Python

3

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill copyleftdev/sk1llz --skill hettinger

  • SKILL.md6.4 KB

Overview

This skill teaches how to write Python in the style of Raymond Hettinger: clear, idiomatic, and composition-oriented. It emphasizes iterators, generators, the collections and itertools toolkits, and small reusable functions to transform messy code into elegant solutions. Use it to refactor, review, or author Python that reads like prose and performs efficiently.

How this skill works

The skill inspects code patterns and suggests Hettinger-style replacements: using collections.Counter/defaultdict/namedtuple, itertools for iterator algebra, generator expressions and pipelines, and functools utilities like lru_cache and wraps. It recommends concrete idioms (enumerate/zip, sum/any/all, operator.itemgetter) and shows how to compose small functions, decorators, and lazy pipelines to reduce memory use and duplication.

When to use it

  • Refactoring imperative code with manual loops, counters, or nested lists
  • Converting eager list-building into lazy generators for large datasets
  • Implementing memoization, decorators, or small reusable abstractions
  • Replacing index-based iteration with enumerate/zip and unpacking
  • Cleaning code to use standard library tools (collections, itertools, functools)

Best practices

  • Prefer built-in tools before custom implementations (collections, itertools, functools)
  • Iterate directly; avoid indexing and single-use lists—use generators when processing streams
  • Compose small pure functions and glue them with generators or itertools
  • Use descriptive names that read like prose and preserve intent
  • Prefer standard patterns: Counter for counting, defaultdict for grouping, lru_cache for memoization

Example use cases

  • Refactor a function that builds large intermediate lists into a generator pipeline to save memory
  • Replace nested loops with itertools.product or chain to simplify control flow
  • Swap manual counting logic for collections.Counter and use most_common for top-k results
  • Create a decorator with wraps for logging, caching, or retry behavior
  • Transform index-based aggregation into enumerate/zip-based, readable code

FAQ

Not always. Hettinger-style idioms often improve readability and reduce memory usage, but measure critical paths; sometimes a specialized approach or data structure is faster for hot loops.

When should I avoid generators?

Avoid generators when you need random access, repeated traversals, or when simple eager lists are clearer and the dataset is small. Use generators for streaming, large data, or composability.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
hettinger skill by copyleftdev/sk1llz | VeilStrat