Skip to content
Skillpedia
General coding48k · #4282

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

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/python/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/python/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
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 python

Or 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.md
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

  1. Comprehensions & Generators
  2. Unpacking & Destructuring
  3. Built-ins & stdlib
  4. Functions & Defaults
  5. Classes & Dataclasses
  6. Error Handling
  7. Type Hints
  8. 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.

repo: sickn33/agentic-awesome-skills

Popularity

GitHub stars
48k
Ranking position
#4282
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills