ワンクリックで
iterate-with-itertools
For combinatorial iteration: permutations, combinations, cartesian products, without storing all results in memory.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
For combinatorial iteration: permutations, combinations, cartesian products, without storing all results in memory.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Conducts iterative deep research on any topic using web search, progressive exploration, and structured synthesis. Use when asked for comprehensive research, deep investigation, thorough analysis, or multi-source exploration of any topic. Triggers: research, investigate, deep dive, comprehensive analysis, explore thoroughly, find everything about.
For cross-cutting concerns: add behavior without modifying functions, caching, timing, logging, validation wrappers.
For performance work: measure before changing, profile to find bottlenecks, compare before and after.
For symbolic computation: ASTs, mathematical expressions, code that manipulates code structure, expression transformations.
For ordered processing: A* search, Dijkstra, event simulation, task scheduling. Efficient min/max extraction with heap-based queue.
For dynamic programming: overlapping subproblems, recursive solutions with repeated computations, memoization to avoid redundant work.
| name | iterate-with-itertools |
| description | For combinatorial iteration: permutations, combinations, cartesian products, without storing all results in memory. |
Use itertools for memory-efficient iteration over combinatorial structures.
from itertools import permutations, combinations, product, chain
# Permutations: all orderings
list(permutations('ABC'))
# [('A','B','C'), ('A','C','B'), ('B','A','C'), ...]
# Combinations: all subsets of size k
list(combinations('ABCD', 2))
# [('A','B'), ('A','C'), ('A','D'), ('B','C'), ('B','D'), ('C','D')]
# Product: cartesian product
list(product('AB', '12'))
# [('A','1'), ('A','2'), ('B','1'), ('B','2')]
# Chain: concatenate iterables
list(chain([1,2], [3,4], [5]))
# [1, 2, 3, 4, 5]
# All are lazy - generate on demand
for perm in permutations(range(10)): # 3.6M permutations
if is_valid(perm):
break # Stop early, don't generate rest
from itertools import permutations, combinations, product
# TSP: try all tours (TSP.ipynb)
def brute_force_tsp(cities):
start, *rest = cities
return min(
([start] + list(perm) for perm in permutations(rest)),
key=tour_length
)
# Card hands (Probability.ipynb)
deck = [r + s for r in 'A23456789TJQK' for s in 'SHDC']
hands = combinations(deck, 5) # 2.6M hands, lazy
# Dice rolls (Probability.ipynb)
def roll(n, sides=6):
"""Distribution of sums from rolling n dice."""
from collections import Counter
die = range(1, sides + 1)
return Counter(sum(roll) for roll in product(die, repeat=n))
# Expression building (Countdown.ipynb)
for L, R in product(left_expressions, right_expressions):
for op in ['+', '-', '*', '/']:
combine(L, op, R)
# Splits of a sequence
def splits(sequence):
"""All ways to split sequence into two non-empty parts."""
return ((sequence[:i], sequence[i:])
for i in range(1, len(sequence)))
product(range(6), repeat=3) for 3 diceislice(permutations(...), 100) for first 100