def _format_items(items, sort=lambda i: i[1], itemmap=lambda i: i):
    """
    Take an array of items and return a string with each item
    and the number of times it occurs in the array.

    Example: ['a', 'a', 'b', 'z', 'z'] => "a (×2), z (×1), b (×1)
    """
    itemstats = {}
    for i in items:
        if not i in itemstats:
            itemstats[i] = 0
        itemstats[i] += 1

    fmtd = []
    for i in sorted(itemstats.items(), key=sort, reverse=True):
        i = (itemmap(i[0]), i[1])
        fmtd.append(f"{i[0]} (×{i[1]})")

    return ", ".join(fmtd)