Pulds1918 Pulds1918 - 1 year ago 91
Python Question

What is the use of lambdas in the zip function

I have seen both

separately but I don't really understand this code:

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

It is taken from:

Answer Source

The code is used for custom sorting of the list. The zip of the contours and boundingBoxes gives a list where the first 2 values represent the x and y coordinates respectively. Hence, by changing i to be 0 or 1, the list can be sorted by the x or y coordinates, which is the purpose of the tutorial.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download