[Python] Python collections.Counter() runtime

Discussão em 'Python' iniciado por Stack, Dezembro 2, 2024.

  1. Stack

    Stack Membro Participativo

    I just run into a problem that I need to put a list, e.g. l = [1, 2, 3, 4], into a dic, e.g. {1: 1, 2: 1, 3: 1, 4: 1}. I just want to know whether I should use collections.Counter() or just write a loop by myself to do this. Is build-in method faster than writing loop by myself?

    Continue reading...

Compartilhe esta Página