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

2007-03-13 Thread Terry Carroll
On Tue, 6 Mar 2007, Alan Gauld wrote: > But I've been up since 4:30am and am too tired to try > figuring it out just now, so maybe someone else will > explain! :-) > > >>> for c in 'abcd': > ...print (c == c in 'crab') > ... > True > True > True > False Trying to understand that, I tried t

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

2007-03-06 Thread Bob Gailer
David Perlman wrote: > On Mar 6, 2007, at 4:28 PM, wesley chun wrote: > > >>> >>> x=('i' in 'i') >>> >>> x >>> True >>> >>> y='i' >>> >>> x==y >>> False >>> >> you're right when you talk about "casting" altho that's not what >> python does. it merely performs an object value comparis

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

2007-03-06 Thread Kent Johnson
David Perlman wrote: > This helps convince me that I still don't understand why the original > code snippet worked at all. :) > > These code examples make perfect sense. This one doesn't, and > appears to be an inconsistency: > > >>> word2 = 'hello' > >>> item = 'e' > >>> item in word2 >

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

2007-03-06 Thread David Perlman
I think it's a little strange and possibly problematic that type(1) is 'int' and type(True) is 'bool' but 1 == True specifically evaluates to True even though anything else, even if it evaluates to True when cast as a boolean, is not == True. >>> 1 == True True >>> 2 == True False >>> 0 ==

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

2007-03-06 Thread John Fouhy
On 07/03/07, David Perlman <[EMAIL PROTECTED]> wrote: > On Mar 6, 2007, at 11:03 AM, Alan Gauld wrote: > > It's doing the latter and since anything that's not 'empty' in > > Python evaluates to true we wind up checking whether > > true == (item in word) > > > > So if the item is in word we get true

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

2007-03-06 Thread David Perlman
On Mar 6, 2007, at 4:28 PM, wesley chun wrote: >> >>> x=('i' in 'i') >> >>> x >> True >> >>> y='i' >> >>> x==y >> False > > you're right when you talk about "casting" altho that's not what > python does. it merely performs an object value comparison when you > use '=='. for example, change

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

2007-03-06 Thread Alan Gauld
"David Perlman" <[EMAIL PROTECTED]> wrote > Sorry, but this still doesn't make sense to me. > >>> x=('i' in 'i') >>> x True >>> y='i' >>> x==y False > But the == operator doesn't cast its operands as Booleans; Good catch! I don't understand it now either. But I've been up since 4:30am and

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

2007-03-06 Thread wesley chun
> >>> x=('i' in 'i') > >>> x > True > >>> y='i' > >>> x==y > False you're right when you talk about "casting" altho that's not what python does. it merely performs an object value comparison when you use '=='. for example, change your code above to: >>> True == 'i'# because this is what

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

2007-03-06 Thread David Perlman
On Mar 6, 2007, at 11:03 AM, Alan Gauld wrote: > It's doing the latter and since anything that's not 'empty' in > Python evaluates to true we wind up checking whether > true == (item in word) > > So if the item is in word we get true == true which is true. > > HTH, Sorry, but this still doesn't ma

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

2007-03-06 Thread Luke Paireepinart
zannah marsh wrote: > what I was trying to do with that loop is check each character in the > string against the corresponding character at the same position in the > second string. rikart pointed out that my loop was actually checking > if that character exists anywhere in the second string. [s

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

2007-03-06 Thread zannah marsh
what I was trying to do with that loop is check each character in the string against the corresponding character at the same position in the second string. rikart pointed out that my loop was actually checking if that character exists anywhere in the second string. basically, in pseudocode: for t

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

2007-03-06 Thread Alan Gauld
"David Perlman" <[EMAIL PROTECTED]> wrote > 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 tr

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

2007-03-06 Thread Luke Paireepinart
David Perlman wrote: > 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 > precedence? > > I can't figure out how this would ever work at a

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

2007-03-06 Thread David Perlman
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 precedence? I can't figure out how this would ever work at all. It seems like it's either

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

2007-03-05 Thread Rikard Bosnjakovic
On 3/6/07, zannah marsh <[EMAIL PROTECTED]> wrote: > step through them as you would in an array or list. so i had this: > for i in word1 > if word1[i] == word2[i]... For this construction to work in Python, you use the range()-function. for index in range(len(word1)): Say word1 i

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

2007-03-05 Thread Rikard Bosnjakovic
On 3/6/07, zannah marsh <[EMAIL PROTECTED]> wrote: > thanks Rikard, that makes sense. No problems, but please post answers to the list and not to my mail adress. This list is braindead that doesn't use a reply-to-tag for the posts, but we've had that debate already so there's no need for another.

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

2007-03-05 Thread Rikard Bosnjakovic
On 3/6/07, zannah marsh <[EMAIL PROTECTED]> 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