cp-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub kobejean/cp-library

:warning: cp_library/alg/iter/counter_fn.py

Code

import cp_library.alg.iter.__header__
from typing import Iterable, Union

def counter(A: Iterable[int] = tuple(), N: Union[int,list[int],None] = None):
    if isinstance(N, int): cnt = [0]*N
    elif N is None: cnt = [0]*(N := max(A := list(A))+1)
    else:  N, cnt = len(N), N
    for a in A: cnt[a] += 1
    return cnt
'''
╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸
             https://kobejean.github.io/cp-library               
'''
from typing import Iterable, Union

def counter(A: Iterable[int] = tuple(), N: Union[int,list[int],None] = None):
    if isinstance(N, int): cnt = [0]*N
    elif N is None: cnt = [0]*(N := max(A := list(A))+1)
    else:  N, cnt = len(N), N
    for a in A: cnt[a] += 1
    return cnt
Back to top page