python
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.
Skill link
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/python/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow can I write a list more concisely in Python?β
5 new skills a week. 1 minute to read.
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.
Technical 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
- #5896
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
00-andruia-consultant
48kHelps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
007
48kLets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
10-andruia-skill-smith
48kHelps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
20-andruia-niche-intelligence
48kLets 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.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.