[Tutor] A list of input arguments
Kent Johnson
kent37 at tds.net
Tue Jan 13 13:42:11 CET 2009
On Tue, Jan 13, 2009 at 6:32 AM, Mr Gerard Kelly
<s4027340 at student.uq.edu.au> wrote:
> My only other question is, does there exist a convenient way to unpack a
> collection of variable length?
>
> If you know that there are 3 elements in the collection, you can specify:
>
> play_for(waves(chord[0],chord[1],chord[2]),500)
>
> But then if you want to change the number of elements in the list
> "chord", say from 3 to 5, you have to change the code accordingly. Is
> there some sort of way to instruct the code to unpack its elements for
> any number of elements?
>
> Like
> i=len(chord)
> play_for(waves(chord[0],chord[1],...,chord[i-1]),500)
Presuming that waves() is defined to take an arbitrary number of arguments, e.g.
def waves(*args)
you can use
play_for(waves(*chord), 500)
to call it with a variable number of arguments.
Kent
More information about the Tutor
mailing list