Disclaimer: I'm looking for a Python 2.6 solution, if there is one.
I'm looking for a function that returns a single value when passed a single value, or that returns a sequence when passed multiple values:
>>> a = foo(1)
2
>>> b, c = foo(2, 5)
>>> b
3
>>> c
6
To be clear, this is in an effort to make some function calls simply look nicer than:
a, = foo(1)
or
a = foo(1)[0]
Right now, the inelegant solution is something along these lines:
def foo(*args):
results = [a + 1 for a in args]
return results if len(results) > 1 else results[0]
Is there any syntactic sugar (or functions) that would make this feel cleaner? anything like the following?
def foo(*args):
return *[a + 1 for a in args]