<Another> Dictionary Question

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Fri Feb 9 05:10:22 EST 2007


On 9 fév, 04:02, "Gabriel Genellina" <gagsl... at yahoo.com.ar> wrote:
> En Thu, 08 Feb 2007 23:32:50 -0300, Sick Monkey <sickcodemon... at gmail.com>
> escribió:
>
> > db = {'b... at gmail.com':'none', '... at yahoo.com':'none',
> > '... at aol.com':'none',
> > '... at gmail.com':'none',}
>
> > And I want to pull out all of the "gmail.com" addresses..  How would I do
> > this?
>
> > NOTE:  I already have a regular expression to search for this, but I feel
> > that looping over a dictionary is not very efficient.

(answer to the OP)

Looping over a dict keys should be quite fast. If you're worried about
perfs, it would be better to first get rid of useless regexps:

filtered_db = dict((k, v) for k, v in db.iteritems() \
                                 if not k.endswith('@gmail.com'))






More information about the Python-list mailing list