(commcare_users_by_domain, n)
return {domain: user_count for user_count, domain in top_domains + [other_entry]}
Reduce (domain => user_count) to n entries, with all other entries summed to a single one

    This allows us to report individual domain data to datadog for the domains that matter
    and report a single number that combines the users for all other domains.

    :param commcare_users_by_domain: the source data
    :param n: number of domains to reduce the map to
    :return: (domain => user_count) of top domains
             with a single entry under () for all other domains
Reduce (domain => user_count) to n entries, with all other entries summed to a single one
Reduce ( domain = > user_count ) to n entries with all other entries summed to a single one
def summarize_user_counts(commcare_users_by_domain, n):
    """
    Reduce (domain => user_count) to n entries, with all other entries summed to a single one

    This allows us to report individual domain data to datadog for the domains that matter
    and report a single number that combines the users for all other domains.

    :param commcare_users_by_domain: the source data
    :param n: number of domains to reduce the map to
    :return: (domain => user_count) of top domains
             with a single entry under () for all other domains
    """
    user_counts = sorted((user_count, domain) for domain, user_count in commcare_users_by_domain.items())
    if n:
        top_domains, other_domains = user_counts[-n:], user_counts[:-n]
    else:
        top_domains, other_domains = [], user_counts[:]
    other_entry = (sum(user_count for user_count, _ in other_domains), ())
    return {domain: user_count for user_count, domain in top_domains + [other_entry]}
def summarize_user_counts ( commcare_users_by_domain , n ) : user_counts = sorted ( ( user_count , domain ) for domain , user_count in commcare_users_by_domain . items ( ) ) if n : top_domains , other_domains = user_counts [ - n : ] , user_counts [ : - n ] else : top_domains , other_domains = [ ] , user_counts [ : ] other_entry = ( sum ( user_count for user_count , _ in other_domains ) , ( ) ) return { domain : user_count for user_count , domain in top_domains + [ other_entry ] }