Is there a better way to code variable number of return arguments?

Simon Forman sajmikins at gmail.com
Thu Oct 8 13:00:25 EDT 2009


On Thu, Oct 8, 2009 at 12:41 PM, Dr. Phillip M. Feldman
<pfeldman at verizon.net> wrote:
>
> 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[0]
> if len(result)==2: return result[0], result[1]
>
> (and so on).  Is there a cleaner way to accomplish the same thing?

It kind of depends on how the caller of your function handles the return values.



More information about the Python-list mailing list