Get occurrences count in list

    0

    6

    Python public recipes

    Get the occurrences of all elements in a list

    >>> from collections import Counter
    >>> z = ['blue', 'red', 'blue', 'yellow', 'blue', 'red']
    >>> Counter(z)
    Counter({'blue': 3, 'red': 2, 'yellow': 1})
    
    from collections import Counter
    
    result = Counter(original_list)
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.