[Python] How does the key argument in python's sorted function work?

Discussão em 'Python' iniciado por Stack, Maio 13, 2025.

  1. Stack

    Stack Membro Participativo

    Say I have

    votes = {'Charlie': 20, 'Able': 10, 'Baker': 20, 'Dog': 15}


    I understand

    print(sorted(votes.items(), key=lambda x: x[1]))


    will lead to

    [('Able', 10), ('Dog', 15), ('Baker', 20), ('Charlie', 20)]


    But how does this work?

    Continue reading...

Compartilhe esta Página