[Tutor] Algorithm

Wayne srilyk at gmail.com
Tue Aug 25 14:17:44 CEST 2009


On Mon, Aug 24, 2009 at 8:58 PM, kreglet <kreglet at gmail.com> wrote:

>
> Wayne,
>
> > def myfunc(cmpword, mainword):
> >   for letter in cmpword:
> >     if mainword.gets(letter):
> >         if cmpword[letter] >mainword[letter]:
> >              return False
> >     else:
> >         return False
>
>  I tried your function and couldn't get it to work. It threw an error in
> the
> line "if mainword.gets(letter):" saying that "gets" was not an attribute of
> dictionary. I tried it with "if mainword.get(letter):" -- no s but that
> would't work either.


sorry, 'get' is what I meant. You also need to add "return True" on the same
level as the else.

In [5]: word1 = {'d':1, 'o':1, 'g':1}

In [6]: word2 = {'g':1, 'o':1}

In [7]: in_word(word2, word1)
Out[7]: True

In [24]: word2 = {'b':1, 'a':1, 'r':1}

In [25]: in_word(word2, word1)
Out[25]: False

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090825/30e44af5/attachment.htm>


More information about the Tutor mailing list