Is there a better way to code variable number of return arguments?
Alan G Isaac
alan.isaac at gmail.com
Fri Oct 9 05:42:52 CEST 2009
Dr. Phillip M. Feldman writes:
> I currently have a function that uses a list internally but then returns the
> list items as separate return
> values as follows:
> if len(result)==1: return result
> if len(result)==2: return result, result
> (and so on). Is there a cleaner way to accomplish the same thing?
The suggestions to return result
or if needed tuple(result) are good,
if a sequence is expected.
But perhaps better if each element has separate meaning:
return a defaultdict;
document the keys.
More information about the Python-list