forwarding *arg parameter

Tuomas tuomas.vesterinen at pp.inet.fi
Sun Nov 5 14:35:58 EST 2006


Stargaming wrote:
> Either you take one of the snippets here:
> http://aspn.activestate.com/ASPN/search?query=flatten&section=PYTHONCKBK&type=Subsection 
> 
> or just use arg[0] clever (as mentioned a few times in this thread).

Thanks. My solution became:

 >>> def flattern(arg):
...     result = []
...     for item in arg:
...         if isinstance(item, (list, tuple)):
...             result.extend(flattern(item))
...         else:
...             result.append(item)
...     return tuple(result)
...
 >>> def g(*arg):
...     arg = flattern(arg)
...     return arg
...
 >>> def f(*arg):
...     return g(arg)
...
 >>> f('foo', 'bar')
('foo', 'bar')

TV



More information about the Python-list mailing list