Skip to content

Add dice[value] indexing to Dice#19

Merged
koaning merged 1 commit into
mainfrom
koaning/dice-getitem-support
Jul 21, 2026
Merged

Add dice[value] indexing to Dice#19
koaning merged 1 commit into
mainfrom
koaning/dice-getitem-support

Conversation

@koaning

@koaning koaning commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Adds __getitem__ to Dice so dice[outcome] returns that outcome's probability. It uses dict-like semantics, raising KeyError for an outcome the dice cannot produce (use .probs.get(outcome, 0) for a zero default). The method is added in the source notebook nbs/__init__.py and regenerated into dicekit/__init__.py via make build, with a new test_dice_getitem covering both the hit and the KeyError cases.

🤖 Generated with Claude Code

Adds __getitem__ so `dice[outcome]` returns that outcome's probability,
raising KeyError for outcomes the dice cannot produce (dict-like semantics).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@koaning
koaning merged commit 65f363c into main Jul 21, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant