[Python] Python: how to get sorted count of items in a list?

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

  1. Stack

    Stack Membro Participativo

    In Python, I've got a list of items like:

    mylist = [a, a, a, a, b, b, b, d, d, d, c, c, e]


    And I'd like to output something like:

    a (4)
    b (3)
    d (3)
    c (2)
    e (1)


    How can I output a count and leaderboard of items in a list? I'm not too bothered about efficiency, just any way that works :)

    Thanks!

    Continue reading...

Compartilhe esta Página