Newbie here... getting a count of repeated instances in a list.

Peter Otten __peter__ at web.de
Mon Nov 24 03:05:31 EST 2003


Amy G wrote:

> I might like to know not only that they are over the threshold, but what
> their actual count is.

Generate a list of (domain, frequency) tuples:

def filter_domains2(domains, threshold=10):
    result = [(d, f) for d, f in domains.iteritems() if f >= threshold]
    result.sort()
    return result

And use it like so:

    for dom, freq in  filter_domains2(domain_histogram, threshold):
        print dom, "->", freq

Peter




More information about the Python-list mailing list