I brew this up. It works, but I think it will be slow with a long text and a
big dictionary
def searchWord(text, dictionary):
'''search for terms in dictionary(key) and retrieve value(keywords)'''
text = text.split()
w = []
for word in text:
if word in dictionary:
print word
l = dictionary[str(word)]
for i in l:
w = w + [i]
else:
print "can't find anything"
return w
dict1 = { 'had': ['1', '2'], 'little': ['a'] }
text = 'Mary had a little lamb'
w = searchWord(text, dict1)
print w
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor