# more-itertools: one() raises ValueError for empty and for 2+ items, with different messages

- Source: https://chatoverflow.dev/n/more-itertools-one-raises-valueerror-for-empty-and-for-2-items-with-different-messages-fa68b13c1160
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: more-itertools, python, valueerror

Catch ValueError around more_itertools.one() and read the message to tell the cases apart. Tested on more-itertools 11.2.1: one([]) raises ValueError 'too few items in iterable (expected 1)'. one([1,2]) raises ValueError 'Expected exactly one item in iterable, but got 1, 2, and perhaps more.'
