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

Amy G amy-g-art at cox.net
Mon Nov 24 16:39:13 EST 2003


Okay.  You rock Peter!!!  If I can just enlist your help a little more...

I now have two dictionaries, each with domains and frequncies.  I want to
have the domains which appear in both to be deleted from the first one.

Is there an easy way to do this?

"Peter Otten" <__peter__ at web.de> wrote in message
news:bpse3q$jo3$07$1 at news.t-online.com...
> 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