You're not actually unzipping when you do zip(*your_list)
. You're still zipping.
zip
is a function that can take as many arguments as you want. In your case, you essentially have four different sequences that you want to zip: ('a', 1)
, ('b', 2)
, ('c', 3)
and ('d', 4)
. Thus, you want to call zip
like this:
>>> zip(('a', 1), ('b', 2), ('c', 3), ('d', 4))
[('a', 'b', 'c', 'd'), (1, 2, 3, 4)]
But your sequences aren't in separate variables, you just have a list which contains them all. This is where the *
operator comes in. This operator unpacks the list in a way that each element of your list becomes an argument to the function.
This means that when you do this:
your_list = [('a', 1), ('b', 2), ('c', 3), ('d', 4)]
zip(*your_list)
Python calls zip
which each element of your list as an argument, like this:
zip(('a', 1), ('b', 2), ('c', 3), ('d', 4))
This is why an unzip
function isn't necessary: Unzipping is just another kind of zip, and is easily achievable with just the zip
function and the *
operator.