On 21/06/2011 12:51, Gurpreet Singh wrote:
Perhaps this is the simplest and best solution which appears in this case. Just 
copy the desired items to a new dictionary and discard the original one.

import re
myDict={'a':'alpha','b':'beta','c':'charley','d':'disney'}
myNewDict={}
for k,v in myDict.iteritems():
     if re.search("a",v)!=None:
        myNewDict[k]=v
print myDict
print myNewDict

Using regex is overkill. Try this instead:

    if "a" in v:
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to