I have a list of dictionaries:
AccountValues = [
{'portfolio_ref': 1, 'tag': 'FullInit', 'value': '20642.95', 'currency': 'USD', 'percent': 0.0},
{'portfolio_ref': 1, 'tag': 'FullMaint', 'value': '21350.54', 'currency': 'USD', 'percent': 0.0},
{'portfolio_ref': 1, 'tag': 'NetLiq', 'value': '70976.05', 'currency': 'USD', 'percent': 100.0} ]
Simple mission per SQL description: Order by portfolio_ref ASC, percent DESC
What I tried unsuccessfully:
sorted(AccountsValues, key=lambda x: (x[1],-x[4]))
which gives me
KeyError: 1
Second attempt:
import operator
result = sorted(myAccountsValues, key=itemgetter('percent'))
which fails to sort on percentage.