Complete AI TrainingYourJobSkills for your job

Skills / super-code

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

  1. [Comprehensions & Generators](#comprehensions)
  2. [Unpacking & Destructuring](#unpacking)
  3. [Built-ins & stdlib](#builtins)
  4. [Functions & Defaults](#functions)
  5. [Classes & Dataclasses](#classes)
  6. [Error Handling](#errors)
  7. [Type Hints](#types)
  8. [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

Sourcecommunity
License
Risk labelsafe ("critical" means the skill may run commands or touch files — read before use)
FilesSKILL.md
Added2026-06-16

Related skills

bash

Language-specific super-code guidelines for bash.

c

Language-specific super-code guidelines for c.

cpp

Language-specific super-code guidelines for cpp.

csharp

Language-specific super-code guidelines for csharp.

dart

Language-specific super-code guidelines for dart.

elixir

Language-specific super-code guidelines for elixir.