# I have a list...

Discussion in 'Python' started by Damir Hakimov, Jul 1, 2003.

1. ### Damir HakimovGuest

Hi, All!

say, i have a function:

def f(*b):
print b
return

then i do:
f(3,4,5)
(3, 4, 5)

but i have list f=(3,4,5)
f(l)
((3, 4, 5),)

how can i call f function to result
f(???(b))
(3, 4, 5)

Thanks!

Damir Hakimov, Jul 1, 2003

2. ### Albert HofkampGuest

On Tue, 1 Jul 2003 11:39:15 +0400, Damir Hakimov <> wrote:
> Hi, All!
>
> say, i have a function:
>
> def f(*b):
> print b
> return
>
> then i do:
> f(3,4,5)
> (3, 4, 5)
>
> but i have list f=(3,4,5)
> f(l)
> ((3, 4, 5),)
>
> how can i call f function to result
> f(???(b))
> (3, 4, 5)

You mean apply(f,(3,4,5)) ?

Albert
--
Unlike popular belief, the .doc format is not an open publically available format.

Albert Hofkamp, Jul 1, 2003

3. ### Guest

Damir Hakimov wrote:
> Hi, All!
>
> say, i have a function:
>
> def f(*b):
> print b
> return
>
> then i do:
> f(3,4,5)
> (3, 4, 5)
>
> but i have list f=(3,4,5)
> f(l)
> ((3, 4, 5),)
>
> how can i call f function to result
> f(???(b))
> (3, 4, 5)
>
> Thanks!
>
>
>

You can use the keyword 'type' to check the type of your arguments
and return the appropriate 'format' according to the their types

Regards

Salvatore

, Jul 1, 2003
4. ### DialtoneGuest

"Damir Hakimov" <> writes:

> say, i have a function:
>
> def f(*b):
> print b
> return
>
> then i do:
> f(3,4,5)
> (3, 4, 5)

This is not a list but a tuple.

> but i have list f=(3,4,5)
> f(l)
> ((3, 4, 5),)

The standard way to represent a tuple with one element is to put a coma
after that element like ("donald",)

> how can i call f function to result
> f(???(b))
> (3, 4, 5)

If you want this you should use a list which has square brackets [].

But the arguments passed with *b are incapsuleted into a tuple so you should
print something like this:

>>> def f(*b):

.... print b[0]

>>> f([1,2,3])

[1, 2, 3]

--
try: troll.uses(Brain)
except TypeError, data:
troll.plonk()
Linux User #310274, Debian Sid Proud User

Dialtone, Jul 1, 2003
5. ### Duncan BoothGuest

"Damir Hakimov" <> wrote in
news::

> Hi, All!
>
> say, i have a function:
>
> def f(*b):
> print b
> return
>
> then i do:
> f(3,4,5)
> (3, 4, 5)
>
> but i have list f=(3,4,5)
> f(l)
> ((3, 4, 5),)
>
> how can i call f function to result
> f(???(b))
> (3, 4, 5)
>

I'm not sure any of the other responses actually answered the question,
which I think was meant to be, given a tuple l=3,4,5 how do you pass that
tuple to the function f so that b simply gets the tuple. The answer is that
you try:

>>> f(*l)

(3,4,5)

If you (or your users) really can't upgrade you should use 'apply'.

--
Duncan Booth
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

Duncan Booth, Jul 1, 2003
6. ### AahzGuest

In article <>,
Damir Hakimov <> wrote:
>
> [...]

....it never will be missed.
--
Aahz () <*> http://www.pythoncraft.com/

Apologies to G&S and everyone reading this.

Aahz, Jul 1, 2003
7. ### Bengt RichterGuest

On Tue, 1 Jul 2003 11:39:15 +0400, "Damir Hakimov" <> wrote:

>Hi, All!
>
>say, i have a function:
>
>def f(*b):
> print b
> return
>
>then i do:
>f(3,4,5)
>(3, 4, 5)
>
>but i have list f=(3,4,5)
>f(l)
>((3, 4, 5),)
>
>how can i call f function to result
>f(???(b))
>(3, 4, 5)
>

Is this what you are looking for? :

>>> def f(*b):

... print b
...
>>> tup = (1,2,3)
>>> f(tup)

((1, 2, 3),)

tup was single arg, but:

>>> f(*tup)

(1, 2, 3)

tup got unpacked to make args

>>> L = [4,5,6]
>>> f(L)

([4, 5, 6],)

L was single arg, but:

>>> f(*L)

(4, 5, 6)

L got unpacked similarly, but note that args become tuple b, not a list.

Regards,
Bengt Richter

Bengt Richter, Jul 2, 2003