from collections import defaultdict


def count_by(iterable, iteratee):
    """
    Think of it like a harry potter sorting hat, tells you final number of students in every group.
    Similar to group_by, instead of returning a list with every grouped_key, returns count of grouped elements only.

    params: array, iteratee
        iterable-> list, set, generator 
        iteratee-> a function or a lambda for grouping the elements

    Examples
    >>> _.count_by([1, 2, 3, 4, 5], lambda x: 'even' if x % 2 == 0 else 'odd')
    >>> {"odd": 3, "even": 2}
    """
    d = defaultdict(lambda: 0)
    for item in iterable:
        key = iteratee(item)
        d[iteratee(item)] += 1
    return dict(d)