I created a utility function to return the expected single item from an generator expression
print one(name for name in ('bob','fred') if name=='bob')
Is this a good way to go about it?
def one(g):
try:
val = g.next()
try:
g.next()
except StopIteration:
return val
else:
raise Exception('Too many values')
except StopIteration:
raise Exception('No values')