python
Language-specific super-code guidelines for python.
Python: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for python.
Table of Contents
- [Comprehensions & Generators](#comprehensions)
- [Unpacking & Destructuring](#unpacking)
- [Built-ins & stdlib](#builtins)
- [Functions & Defaults](#functions)
- [Classes & Dataclasses](#classes)
- [Error Handling](#errors)
- [Type Hints](#types)
- [Anti-patterns specific to Python](#antipatterns)
1. Comprehensions & Generators {#comprehensions}
# ❌ Imperative accumulation
result = []
for item in items:
if item.active:
result.append(item.name.upper())
# ✅
result = [item.name.upper() for item in items if item.active]
# ❌ Dict built in a loop
d = {}
for k, v in pairs:
d[k] = v
# ✅
d = dict(pairs)
# or
d = {k: v for k, v in pairs}
# ❌ Generator converted to list unnecessarily
total = sum(list(x * 2 for x in nums))
# ✅ — generator expression works directly in sum()
total = sum(x * 2 for x in nums)
Use generator expressions (not list comprehensions) when the result is consumed once and not stored.
2. Unpacking & Destructuring {#unpacking}
# ❌ Index access
first = items[0]
rest = items[1:]
# ✅
first, *rest = items
# ❌ Temporary variable for swap
tmp = a
a = b
b = tmp
# ✅
a, b Subscribers only
The full skill, its 1 bundled files and every download is included with every paid Complete AI plan.
Details
| Source | community |
|---|---|
| License | — |
| Risk label | safe ("critical" means the skill may run commands or touch files — read before use) |
| Files | SKILL.md |
| Added | 2026-06-16 |
