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:
zip(*[(3,7,35),(4,11,8)])
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.