Splice two lists

Ben Cartwright bencvt at gmail.com
Sun May 7 01:05:08 EDT 2006


danmcleran at yahoo.com wrote:
> Thanks, this worked great.

Welcome. :-)

> Can you explain the syntax of the '*' on the
> return value of izip? I've only ever seen this syntax with respect to
> variable number of args.

When used in a function call (as opposed to a function definition), *
is the "unpacking" operator.  Basically, it "flattens" an iterable into
arguments.  The docs mention it...

http://www.python.org/doc/2.4.2/tut/node6.html#SECTION006740000000000000000
http://www.python.org/doc/faq/programming/#how-can-i-pass-optional-or-keyword-parameters-from-one-function-to-another

...but not in great detail.  You can apply * to an arbitrary
expression, e.g.:

  >>> def f3(a, b, c): pass

  >>> f3(1, 2, 3)
  >>> f3(*range(3))
  >>> f3(*[1, 2, 3])

--Ben




More information about the Python-list mailing list