[Tutor] Feeding a list into a function as arguments

Andre Engels andreengels at gmail.com
Thu Apr 26 10:42:29 CEST 2007


2007/4/26, Stevie Broadfoot <coollikestevie at gmail.com>:
> I have a list... say for example
>
> list = ["hello", "there"]
>
> and i have a function
>
> def printout(firstword, secondword):
>     print firstword
>     print secondword
>
> and i want to call
>
> the function like this
>
> printout(list)
>
> but that doesnt work because it takes the list as an argument.
>
> How can I get around this problem?

I see two simple ways, maybe there are more:

1. simply use
printout(list[0],list[1])

2. Change the definition of printout to:

def printout(firstword, secondword = None):
    if secondword is None:
        (firstword,secondword) = firstword
    print firstword
    print secondword


--
Andre Engels, andreengels at gmail.com
ICQ: 6260644  --  Skype: a_engels


More information about the Tutor mailing list