zip asterisk syntax

C

Christopher T King

garett said:
Hello, I have been reading text processing in python and in the appendix
the author describes:
sides = [(3, 4), (7, 11), (35, 8)]
zip(*zip(*sides))

what is this asterisk-list syntax called? Any suggestions for finding more
information about it? Thanks. -Garett

It's called the "extended function call" syntax. Basically what it does
is take the items of a list and use them as arguments to a function.
Let's take the example above:
sides = [(3, 4), (7, 11), (35, 8)]
zip(*zip(*sides))

is the same as:

zip() mangles its arguments in such a way that the above call is
equivalent to this:

which is the same as:

which evaluates to [(3,4),(7,11),(35,8)].

Back on topic, the dictionary equivalent of * is **; that is, ** takes the
key-value pairs from a dictionary and uses them as arguments to a
function. * and ** must appear after other arguments to the function, and
you may only have at most one each of * and **.

There's another context other than function calls in which * and ** can be
used, and that's function definitions:

will pack any extra arguments (beyond a and b) into list c and dictionary
d.

For (very) detailed information, see http://docs.python.org/ref/calls.html
and http://docs.python.org/ref/function.html.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top