[Python] Sorting Dictionary By Date

Discussão em 'Python' iniciado por Stack, Abril 22, 2025.

  1. Stack

    Stack Membro Participativo

    I have a dictionary which contains several years of data. The dictionary is basically this:

    data = {
    '2024-09-20': 13.37,
    '2024-09-21': 14.92,
    '2024-09-22': 15.17,
    '2024-09-23': 12.15
    }


    It contains about 10 years of data or so. What I need to do is first limit the range to just the last 5 years, and then choose the largest value.

    So, I need to sort it by the key, which is the date in DESC order, then remove anything greater than 5 years, then choose the largest value.

    Continue reading...

Compartilhe esta Página