My favorite function here is more_itertools.one. Especially in something like a unit test, where ValueErrors from unexpected conditions are desirable, we can use it to turn code like<p><pre><code> results = list(get_some_stuff(...))
assert len(results) = 1
result = results[0]
</code></pre>
into<p><pre><code> result = one(get_some_stuff(...))
</code></pre>
I guess you could also use tuple-unpacking:<p><pre><code> result, = get_some_stuff(...)
</code></pre>
But the syntax is awkward to unpack a single item. Doesn't that trailing comma just look implausible? (Also I've worked with type-checkers that will complain when a tuple-unpacking could potentially fail, while one has a clear type signatures Iterable[T] -> T.)