Reputation: 1053
I have list with different elements (string and float), an example:
X = [['carrier', 'arrivaldelay', 'MAX', 0.43085409548228853],
['carrier', 'weatherdelay', 'SUM', 0.45040808607625615],
['carrier', 'arrivaldelay', 'SUM', 0.4166832477676661],
['destination', 'departurdelay', 'MAX', 0.4009409407356311],
['destination', 'arrivaldelay', 'AVG', 0.4216147060142493],
['origin', 'arrivaldelay', 'AVG', 0.4353396150129142],
['origin', 'arrivaldelay', 'MIN', 0.4157363968474399],
['origin', 'arrivaldelay', 'STD', 0.4478847651966835]]
What is the simple and efficient way to get the list which has minimum value based on the last value,
Expected output : ['destination', 'departurdelay', 'MAX', 0.4009409407356311]
Upvotes: 0
Views: 147
Reputation: 888
Most simple I can think of:
min(X, key=lambda x: x[-1])
Upvotes: 5