recursive function call
Nicolas Vigier
boklm at mars-attacks.org
Tue Nov 8 07:54:16 EST 2005
Peter Otten said:
> Here is a non-recursive approach:
>
> def tolist(arg):
> if isinstance(arg, list):
> return arg
> return [arg]
>
> def f(arg1, arg2, more_args):
> for arg1 in tolist(arg1):
> for arg2 in tolist(arg2):
> # real code
>
> If it were my code I would omit the tolist() stuff and instead always
> pass lists (or iterables) as the function's first two arguments.
Hmm, that's right. After all it's not very useful to be able to give
a single element, passing a list all the time is more simple. That's
what I'll do. I got the idea of passing a list or a singe element
because that's what they do in SCons, but in my case it's not really
usefull.
Thanks
--
http://n0x.org/ - boklm at mars-attacks.org
More information about the Python-list
mailing list