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
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
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
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
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
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
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
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 <[
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
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
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
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
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
>
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 ==
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
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
"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
> >>> 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
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
"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
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
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
"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
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
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
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
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.
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
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
29 matches
Mail list logo