python
Enables your agent to program in Python. Essential for automation, data analysis, and web development. It facilitates creating scripts and complex applications.
What it does
This guide helps you write more efficient and clear Python code. It shows how to use language features to make your code shorter and easier to understand, while avoiding common mistakes.
When to use it
- ✓When you want to write cleaner Python code.
- ✓To learn Python shortcuts and best practices.
- ✓When refactoring code to make it more readable.
Example of what to ask your AI
“How can I write a list more concisely in Python?”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
The guide compares 'bad' code examples with 'good' ones that use specific Python features. It suggests simpler, more direct alternatives for common tasks.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add sickn33/agentic-awesome-skills --skill pythonOr download just the file:
curl -L https://raw.githubusercontent.com/sickn33/agentic-awesome-skills/main/plugins/agentic-awesome-skills-claude/skills/super-code/python/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from GitHub.
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
- Unpacking & Destructuring
- Built-ins & stdlib
- Functions & Defaults
- Classes & Dataclasses
- Error Handling
- Type Hints
- Anti-patterns specific to Python
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 = b, a
# ❌ items() with separate indexing
for i in range(len(items)):
print(i, items[i])
# ✅
for i, item in enumerate(items):
print(i, item)
# ❌ zip with separate index
for i in range(len(a)):
process(a[i], b[i])
# ✅
for x, y in zip(a, b):
process(x, y)
3. Built-ins & stdlib {#builtins}
# ❌ Manual max search
max_val = items[0]
for item in items[1:]:
if item > max_val:
max_val = item
# ✅
max_val = max(items)
# ❌ Manual grouping
from collections import defaultdict
groups = defaultdict(list)
for item in items:
groups[item.category].append(item)
# ✅ — same thing, just be explicit about defaultdict; it IS the right tool
# (this example is already correct — don't replace defaultdict with a loop)
# ❌ Manual sentinel for dict default
if key in d:
val = d[key]
else:
val = default
# ✅
val = d.get(key, default)
# ❌ Rolling your own counter
counts = {}
for item in items:
counts[item] = counts.get(item, 0) + 1
# ✅
from collections import Counter
counts = Counter(items)
Use itertools (chain, islice, groupby, product) before writing nested loops for combinatorial or streaming logic.
4. Functions & Defaults {#functions}
# ❌ Mutable default argument (bug, not just style)
def append_to(item, lst=[]):
lst.append(item)
return lst
# ✅
def append_to(item, lst=None):
if lst is None:
lst = []
lst.append(item)
return lst
# ❌ Positional args for everything when keyword clarity helps
create_user("Alice", True, False, 30)
# ✅ — use keyword args at call site for boolean/ambiguous params
create_user("Alice", is_admin=True, is_active=False, age=30)
# ❌ Long function doing multiple things
def process_and_save(data):
# 40 lines of transform
# 20 lines of DB write
...
# ✅ — split only if each part is reused OR independently testable
def _transform(data): ...
def _save(record): ...
def process_and_save(data): _save(_transform(data))
5. Classes & Dataclasses {#classes}
# ❌ Manual __init__ for data holders
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
# ✅
from dataclasses import dataclass
@dataclass
class Point:
x: float
y: float
# ❌ Class just to hold a namespace of functions
class MathUtils:
@staticmethod
def add(a, b): return a + b
# ✅ — module-level functions; classes for state + behavior
def add(a, b): return a + b
# ❌ __repr__ written manually when dataclass gives it free
# (see above — use @dataclass)
Use @dataclass(frozen=True) for immutable value objects. Use NamedTuple when you need tuple unpacking.
6. Error Handling {#errors}
# ❌ Bare except
try:
risky()
except:
pass
# ✅ — catch the specific exception; don't swallow silently
try:
risky()
except ValueError as e:
logger.warning("Invalid value: %s", e)
# ❌ LBYL (look before you leap) when EAFP is cleaner
…
FAQ
What are 'Comprehensions & Generators'?
These are shorter ways to create lists or sequences, replacing traditional loops with a single, more expressive line of code.
What does 'Unpacking & Destructuring' mean?
It's a technique to extract values from lists or tuples directly into variables, making code more readable when dealing with multiple values.
Why should I avoid 'Mutable default arguments'?
Using lists or dictionaries as default values in functions can lead to unexpected behavior because the same object is shared across calls.
Details
Original description by the author
Language-specific super-code guidelines for python.
Popularity
- GitHub stars
- 48k
- Ranking position
- #4282
- License
- MIT
- Updated
- 10/15/2026
Comments
- …
More skills from this repository
00-andruia-consultant
Helps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
sickn33/agentic-awesome-skills
007
Lets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
sickn33/agentic-awesome-skills
10-andruia-skill-smith
Helps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
sickn33/agentic-awesome-skills
20-andruia-niche-intelligence
Lets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
sickn33/agentic-awesome-skills
Similar skills
benchmark-optimization-loop
Has your agent improve something's speed in a measured way. It tests multiple versions and chooses the fastest one that still works correctly.
affaan-m/ECC
change-impact
Helps your agent analyze the impact of code changes before making them. It compares the planned vs. actual results afterward, covering paths, data, tests, and documentation. Useful for risky or system-wide changes.
affaan-m/ECC
click-path-audit
Lets your agent trace all user buttons and interactions to find bugs. It finds issues where functions seem to work alone but fail together. Useful when bugs persist even after debugging.
affaan-m/ECC