Skip to content
Back to skills

Prefer Comprehensions To Append Loops

ASecurity

When a loop's only job is to build a list, write it as a comprehension

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 17, 2026
ai-agentsexpress

Security analysis

A100/100

Scanned October 17, 2026

npx -y skills add samugit83/cortex --skill prefer-comprehensions-to-append-loops --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Prefer Comprehensions To Append Loops?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Prefer Comprehensions To Append Loops
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/samugit83-prefer-comprehensions-to-append-loops/badge)](https://www.skillsdirectory.com/skills/samugit83-prefer-comprehensions-to-append-loops)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: prefer-comprehensions-to-append-loops
description: When a loop's only job is to build a list, write it as a comprehension
---

# Comprehensions

A loop whose body is a single `append` is a comprehension written the long way.

    rows = [f(x) for x in items if keep(x)]

- One `for` and at most one `if` stay readable on one line; past that, the loop
  was carrying real logic and should stay a loop.
- A comprehension that spans more than about three lines is a function that has
  not been named yet.
- Use a generator expression when the result is consumed once and never indexed.

Never use a comprehension for its side effects: that is a loop wearing a
disguise, and the reader will miss it.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.