Re: [Tutor] trouble with function-- trying to check

2007-03-15 Thread Isaac
I see. Thanks for clarifying that for me. -Isaac On 3/15/07, Kent Johnson <[EMAIL PROTECTED]> wrote: Isaac wrote: > In 5.9 of the Language Reference it says: > > "Comparisons can be chained arbitrarily, e.g., |x < y <= z| is > equivalent to |x < y and y <= z" > > |So this would mean that > > i

Re: [Tutor] trouble with function-- trying to check

2007-03-15 Thread Kent Johnson
Isaac wrote: > In 5.9 of the Language Reference it says: > > "Comparisons can be chained arbitrarily, e.g., |x < y <= z| is > equivalent to |x < y and y <= z" > > |So this would mean that > > item == item in word2 > > means: > > item == item and item in word2 > > not > > (item == item) and

Re: [Tutor] trouble with function-- trying to check

2007-03-14 Thread Isaac
Hola, Pardon me if I am repeating others, I think I have read the whole thread now. In 5.9 of the Language Reference it says: "Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z" So this would mean that item == item in word2 means: item == item and it

Re: [Tutor] trouble with function-- trying to check

2007-03-14 Thread Terry Carroll
On Wed, 14 Mar 2007, Kent Johnson wrote: > This has already been discussed on this thread. == and 'in' are comparisons. Aha. I did not see this discussion in the thread; the closest thing I noticed was Alan's note that I was riffing from, which concluded with "It definitely seems to work as I ex

Re: [Tutor] trouble with function-- trying to check

2007-03-14 Thread Isaac
This has already been discussed on this thread. == and 'in' are comparisons. (c == c in 'crab') means (c == c) and (c in 'crab') http://docs.python.org/ref/comparisons.html Kent Re: [Tutor] trouble with function-- trying to check To: Terry Carroll <[EMAIL PROTECTED

Re: [Tutor] trouble with function-- trying to check

2007-03-14 Thread Kent Johnson
Terry Carroll wrote: > On Wed, 14 Mar 2007, Isaac wrote: > >> a, b, c, or d is a type('str') not boolean which is what (c in "crab") is. >> The [in] operator takes presedence, the first 3 times (c in "crab") returns >> true and the last returns false; but the strings a, b, c, or d do not == >> tru

Re: [Tutor] trouble with function-- trying to check

2007-03-14 Thread Terry Carroll
On Wed, 14 Mar 2007, Isaac wrote: > a, b, c, or d is a type('str') not boolean which is what (c in "crab") is. > The [in] operator takes presedence, the first 3 times (c in "crab") returns > true and the last returns false; but the strings a, b, c, or d do not == > true or false - therefore the te

Re: [Tutor] trouble with function-- trying to check

2007-03-14 Thread Isaac
As far as I can tell: because (c in "crab") membership is in parentheses it is more binding than the [==] comparison. That is why it returns true/false first. I incorrectly wrote before: " The [in] operator takes precedence" http://docs.python.org/ref/summary.html -Isaac On 3/14/07, Isaac <[

Re: [Tutor] trouble with function-- trying to check

2007-03-13 Thread Isaac
a, b, c, or d is a type('str') not boolean which is what (c in "crab") is. The [in] operator takes presedence, the first 3 times (c in "crab") returns true and the last returns false; but the strings a, b, c, or d do not == true or false - therefore the test (c == (c in "crab")) always returns fal

Re: [Tutor] trouble with function-- trying to check

2007-03-13 Thread Isaac
a, b, c are all in crab but d is not. >>> for c in 'abcd': ...print (c == c in 'crab') ... True True True False Message: 5 Date: Tue, 13 Mar 2007 13:01:48 -0700 (PDT) From: Terry Carroll <[EMAIL PROTECTED]> Subject: Re: [Tutor] trou

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 differencesbtwn 2 strings

2007-03-06 Thread Alan Gauld
"zannah marsh" <[EMAIL PROTECTED]> wrote > rikart pointed out that you need to use a range to get to the > indicies of > the items in the string. > > for item in range(len(string))... > if word1[item] == word2[item] > There is another way which is to use enumerate which returns both the item

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

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

2007-03-05 Thread zannah marsh
I am very new to Python (I've been learning it for about 2 weeks, in a class). I wrote this function ( as part of a larger program, for my homework) which is supposed to step through two given strings and check for differences between the strings. It returns a list of the indices at which the char