For my application units
and errors
are always lists of numerical values. I tried googling what each part does and figured out the firs part of zip. It seems
ziped_list = zip(units, errors)
simply pairs the units and errors to produce a list as [...,(unit, error),...]
. Then Its passed to sorted which sorts the elements. Since I did not provide the argument for key
, then it compares the elements directly as the documentation implies:
The default value is None (compare the elements directly).
Since the ziped_list
is a list of tuples of integers, then it seems that it makes a comparison between tuples directly. From a small example in my terminal (python 3) it seems it compares based on the first element (even though the documentation implies the comparison is element wise):
>>> (1,None) < (2,None)
True
>>> (2,None) < (1,None)
False
The last bit the unpacking and then zip still remain a mystery and I have not been able to figure out what they do. I understand that *
unpacks to positional argument but doing *
doesn't let me see exactly what its doing if I try it in the command line. What further confuses me is why zip
requires to be passed as argument an unpacked list such as *sorted
if it already takes as an argument zip(*iterable)
a variable called iterable. It just seems confusing (to me) why we would need to unpack something that just allows as input a list of iterables.