On 9/20/2020 6:34 PM, Stavros Macrakis wrote:
I'm trying to improve my Python style.

Consider a simple function which returns the first element of an iterable
if it has exactly one element, and throws an exception otherwise. It should
work even if the iterable doesn't terminate. I've written this function in
multiple ways, all of which feel a bit clumsy.

The 'obvious' thing to me was the double try-except StopIteration. It is clear, and clarity is 'pythonic'.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to