* operator in python tutorial
someone at somewhere.com
Thu Jan 21 02:30:25 CET 2010
On 1/20/2010 12:38, ben wrote:
> I am following through the python tutorial which gets to a line that
> uses the * operator with zip(). I searched and searched but could find
> no information on the operator or how to use it in general. The
> example from the tut is as follows:
>>>> x = [1, 2, 3]
>>>> y = [4, 5, 6]
>>>> zipped = zip(x, y)
> [(1, 4), (2, 5), (3, 6)]
>>>> x2, y2 = zip(*zipped)
>>>> x == list(x2) and y == list(y2)
> How would i apply the * operator in general?
The * operator, when used in this context, unpacks the sequence and it's
as if you passed each item to the function as a different parameter.
For example, if you have a list x with 4 items, these two statements
would be the same:
Hope this helps.
More information about the Python-list