<Another> Dictionary Question

Sick Monkey sickcodemonkey at gmail.com
Thu Feb 8 21:32:50 EST 2007


Hello All.

I have a question concerning searching data within dictionaries.

Lets say I have a dictionary called db.
db = {'blah at gmail.com':'none', 'blah at yahoo.com':'none', 'blah at aol.com':'none',
'blah 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.

So I have:
domsrch = re.compile(r"@(\S+)")
listToLookFor = ['gmail.com']
db = {'blah at gmail.com':'none', 'blah at yahoo.com':'none', 'blah at aol.com':'none',
'blah at gmail.com':'none',}

I wonder if there is a way to do something like
<Psuedo code>
for item in listToLookFor:
   if domsrch.findall(db.has_key( item )):
      print "horray"

NOTE:  I know the findall is for lists, but I dont know of an efficient way
to search for this in a dictionary.

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070208/fa85488d/attachment.html>


More information about the Python-list mailing list