[Tutor] matching words from a text to keys in a dictionary
spir
denis.spir at gmail.com
Mon Mar 8 17:59:03 CET 2010
On Mon, 8 Mar 2010 08:05:54 -0800 (PST)
Karjer Jdfjdf <karper12345 at yahoo.com> wrote:
> I want to compare words in a text to a dictionary with values attached to the words.
>
> The dictionary looks like:
> { word1: [1,2,3] word2: [2,3,4,a,b ] ... }
And how does your source text look like? (we have half of the data)
And please print (part of) your dict out (instead of providing erroneous data).
> I'm trying to find a way to achieve this, but I'm having trouble getting corrects results.
>
> If I do the def below, nothing is matched.
>
> def searchWord(text, dictionary):
> text = text.split()
> for word in text:
> print word
print word, word in dictionary # would be useful for debug
> if word in dictionary:
> value = dictionary[str(word)]
word is already a string -- or should be ;-)
> else:
> value = None
> return w
What is w? This is your main issue, I guess...
[...]
Denis
--
________________________________
la vita e estrany
spir.wikidot.com
More information about the Tutor
mailing list