[Tutor] Feeding a list into a function as arguments

Kent Johnson kent37 at tds.net
Thu Apr 26 18:14:25 CEST 2007


Kent Johnson wrote:
> Stevie Broadfoot wrote:
>> actually scrap that, it works perfectly :) thank you very much for your 
>> help. One last question, does this only work on lists? or will tuples 
>> work too and what else?
> 
> It will work on any sequence including lists and tuples.

More precisely, it will work with any iterable - even a dict (which 
passes the *keys* of the dict) or a generator expression:

In [14]: def p(*args):
    ....:     print args
    ....:
    ....:
In [15]: p(*dict(foo=1, bar=2))
('foo', 'bar')
In [16]: p(*(x*x for x in range(4)))
(0, 1, 4, 9)

Kent


More information about the Tutor mailing list