Steven Lee Steven Lee - 2 months ago 13
Python Question

Python asterisk before function

I am following this tutorial:

http://www.pyimagesearch.com/2015/04/20/sorting-contours-using-python-and-opencv/#comment-405768

and in one of the lines there is the function:

(cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),
key=lambda b:b[1][i], reverse=reverse))


I want to know what is the use of the asterisk before the
sorted
function call.

Answer

You need to understand what the code is trying to do. The first part sorted(zip(cnts, boundingBoxes) creates a sorted list which is the zipped version of contours and boundingBoxes. The asterisk "unzips" it so that the outer zip can produce the correct output.

Comments