summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/pure/c_arrays.py
blob: f221b7ae853cded7870ad35dbc981660b6f37a31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import cython


@cython.locals(counts=cython.int[10], digit=cython.int)
def count_digits(digits):
    """
    >>> digits = '01112222333334445667788899'
    >>> count_digits(map(int, digits))
    [1, 3, 4, 5, 3, 1, 2, 2, 3, 2]
    """
    counts = [0] * 10
    for digit in digits:
        assert 0 <= digit <= 9
        counts[digit] += 1
    return counts