[Tutor] trouble with function-- trying to check differences btwn 2 strings

David Perlman dperlman at wisc.edu
Tue Mar 6 14:21:59 CET 2007

OK, I'm new to python too so I don't assume I know what I'm talking  
about yet, but this looks like a mess to me.  What exactly does "item  
== item in word2" evaluate to?  Does "in" or "==" have higher  

I can't figure out how this would ever work at all.  It seems like  
it's either checking to see whether boolean TRUE is in word2, or else  
it's checking to see whether item is equal to boolean TRUE or FALSE,  
and neither of those should ever be true.  And yet it seems to be  
working out the same as "item in word2".  So what exactly is python  
doing here?

On Mar 5, 2007, at 5:13 PM, Rikard Bosnjakovic wrote:

> On 3/6/07, zannah marsh <zannah.m at gmail.com> wrote:
>>         if item == item in word2: #checks characters against each  
>> other
> Here's the error.
> Loop variable "item" contains the actual character in word1. The
> syntax "item in word2" checks if this character is _anywhere_ in
> word2. What you want to do is rewriting this loop so it checks
> character per character. Since it's for homework, I don't want to ruin
> your grades by giving you a solution. Try it yourself first.
> To see what I mean, try running getDiff("abcd", "dcba").
> -- 
> - Rikard.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

After all, it is not *that* inexpressible.
-H.H. The Dalai Lama

More information about the Tutor mailing list