<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">I brew this up. It works, but I think it will be slow with a long text and a big dictionary<br><br><div class="plainMail">def searchWord(text, dictionary):<br> '''search for terms in dictionary(key) and retrieve value(keywords)'''<br> text = text.split()<br> w = []<br> for word in text:<br> if word in dictionary:<br> print word<br> l = dictionary[str(word)]<br> for i in l:<br> w = w +
[i] <br> else:<br> print "can't find anything"<br><br> return w<br><br><br>dict1 = { 'had': ['1', '2'], 'little': ['a'] }<br>text = 'Mary had a little lamb'<br><br>w = searchWord(text, dict1)<br>print w<br><br><br></div></td></tr></table><br>