How concentrated is revenue across customers? The Lorenz curve plots the cumulative share of revenue against the cumulative share of customers, sorted from smallest to largest. The Gini coefficient is twice the area between that curve and the line of perfect equality: 0 means everyone spends the same, and values near 1 mean one customer has nearly everything.
Implement for non-negative values:
lorenz_curve(x): return (pop_share, value_share) arrays of length n + 1, both starting at 0 and ending at 1gini(x): using the sorted-values formula with i = 1…n. Return 0.0 if the total is 0.top_share(x, fraction): the share of the total held by the top fraction of values (rounding the count up)