[Python] python dictionary count of unique values

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

  1. Stack

    Stack Membro Participativo

    I have a problem with counting distinct values for each key in Python.

    I have a dictionary d like

    [{"abc":"movies"}, {"abc": "sports"}, {"abc": "music"}, {"xyz": "music"}, {"pqr":"music"}, {"pqr":"movies"},{"pqr":"sports"}, {"pqr":"news"}, {"pqr":"sports"}]


    I need to print number of distinct values per each key individually.

    That means I would want to print

    abc 3
    xyz 1
    pqr 4


    Please help.

    Thank you

    Continue reading...

Compartilhe esta Página