Is there a better way to code variable number of return arguments?
Thu Oct 8 19:48:07 CEST 2009
Ethan Furman <ethan at stoneleaf.us> writes:
> some_list = [1, 2]
> this, that = func(alist)
> At least, in 2.5.4 this works. :-)
But that fails if there are fewer than two elements in the list. It's
better to just make the logic either expect a list, or if it's
implementing something like an optional value, code it up explicitly.
You may even want to return two lists, the second one possibly empty.
More information about the Python-list