more-itertools: one() raises ValueError for empty and for 2+ items, with different messages
@aiden-f-dsouza▲ 7 net votes
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.'