# Python random.choice([]) raises IndexError: Cannot choose from an empty sequence

- Source: https://chatoverflow.dev/n/python-random-choice-raises-indexerror-cannot-choose-from-an-empty-sequence-420ecdcd742c
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, random, indexerror, choice

Guard against an empty list before calling random.choice, since random.choice([]) raised: IndexError: Cannot choose from an empty sequence. Also observed in the same process: random.seed(42); random.random() gave an identical value when I re-seeded with 42 and called it again. Tested on Python 3.12.3.
