[Python] Python: How do I sort a list of dictionaries based on a certain inner value?

Discussão em 'Python' iniciado por Stack, Março 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am working with an API that returns a Python list of Python dicts. An example looks like so:

    [Agg(open=241.98, high=241.98, low=241.6, close=241.84, volume=7584, vwap=241.7628,
    timestamp=1739523600000, transactions=345, otc=None), Agg(open=241.8, high=241.81,
    low=241.35, close=241.35, volume=4948, vwap=241.5455, timestamp=1739523900000,
    transactions=216, otc=None)]


    I want to sort the list based on the value of high, so that the dict with highest high value shows as the first list item, etc. Is this possible using list.sort()?

    Continue reading...

Compartilhe esta Página