Verify only one element in iterable
suggest changeUse unpacking to extract the first element and ensure it’s the only one:
a, = iterable
def foo():
yield 1
a, = foo() # a = 1
nums = [1, 2, 3]
a, = nums # ValueError: too many values to unpack
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents