Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96672 > unrolled thread

True == 1 weirdness

Started by"Blake T. Garretson" <blake.garretson@gmail.com>
First post2015-09-16 05:16 -0700
Last post2015-09-17 00:57 +1000
Articles 4 on this page of 84 — 17 participants

Back to article view | Back to comp.lang.python


Contents

  True == 1 weirdness "Blake T. Garretson" <blake.garretson@gmail.com> - 2015-09-16 05:16 -0700
    Re: True == 1 weirdness Jussi Piitulainen <harvesting@makes.email.invalid> - 2015-09-16 15:53 +0300
      Re: True == 1 weirdness Chris Angelico <rosuav@gmail.com> - 2015-09-16 23:05 +1000
      Re: True == 1 weirdness "Blake T. Garretson" <blake.garretson@gmail.com> - 2015-09-16 06:14 -0700
      Re: True == 1 weirdness Random832 <random832@fastmail.com> - 2015-09-16 10:03 -0400
        Re: True == 1 weirdness Steven D'Aprano <steve@pearwood.info> - 2015-09-17 03:24 +1000
          Re: True == 1 weirdness Random832 <random832@fastmail.com> - 2015-09-16 13:36 -0400
          Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-16 19:57 +0200
          Re: True == 1 weirdness Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-16 11:57 -0600
      Re: True == 1 weirdness Chris Angelico <rosuav@gmail.com> - 2015-09-17 00:26 +1000
        Re: True == 1 weirdness Marko Rauhamaa <marko@pacujo.net> - 2015-09-16 19:16 +0300
          Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-16 18:37 +0200
            Re: True == 1 weirdness Marko Rauhamaa <marko@pacujo.net> - 2015-09-16 19:53 +0300
              Re: True == 1 weirdness Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-09-17 18:30 +1200
          Re: True == 1 weirdness Random832 <random832@fastmail.com> - 2015-09-16 12:57 -0400
            Re: True == 1 weirdness Steven D'Aprano <steve@pearwood.info> - 2015-09-17 03:39 +1000
              Re: True == 1 weirdness Marko Rauhamaa <marko@pacujo.net> - 2015-09-16 20:42 +0300
                Re: True == 1 weirdness Emile van Sebille <emile@fenx.com> - 2015-09-16 11:46 -0700
              Re: True == 1 weirdness Grant Edwards <invalid@invalid.invalid> - 2015-09-16 17:46 +0000
                Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-16 20:13 +0200
                  Re: True == 1 weirdness Grant Edwards <invalid@invalid.invalid> - 2015-09-16 19:47 +0000
                    Re: True == 1 weirdness Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-16 21:25 +0100
                      Re: True == 1 weirdness Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-09-17 18:36 +1200
                    Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-16 23:05 +0200
                      Re: True == 1 weirdness Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-09-17 18:39 +1200
                        Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-17 22:46 +0200
                        Re: True == 1 weirdness Tim Chase <python.list@tim.thechases.com> - 2015-09-17 16:26 -0500
                        Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-17 23:52 +0200
                    Re: True == 1 weirdness Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-16 22:30 +0100
                    Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-17 00:15 +0200
                    Re: True == 1 weirdness Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-17 01:06 +0100
                      Re: True == 1 weirdness Steven D'Aprano <steve@pearwood.info> - 2015-09-17 11:33 +1000
                        Re: True == 1 weirdness Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-17 10:56 +0100
                          Re: True == 1 weirdness alister <alister.nospam.ware@ntlworld.com> - 2015-09-17 12:07 +0000
                            Re: True == 1 weirdness Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-17 13:27 +0100
                      Re: True == 1 weirdness Steven D'Aprano <steve@pearwood.info> - 2015-09-17 12:34 +1000
                    Re: True == 1 weirdness Chris Angelico <rosuav@gmail.com> - 2015-09-17 10:53 +1000
                      Re: True == 1 weirdness Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-09-17 18:42 +1200
                    Re: True == 1 weirdness Emile van Sebille <emile@fenx.com> - 2015-09-16 18:12 -0700
                    Re: True == 1 weirdness Tim Chase <python.list@tim.thechases.com> - 2015-09-16 18:10 -0500
              Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-16 19:53 +0200
                Re: True == 1 weirdness Marko Rauhamaa <marko@pacujo.net> - 2015-09-16 22:47 +0300
              Re: True == 1 weirdness Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-16 21:29 +0100
              Re: True == 1 weirdness Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-16 22:27 +0100
          Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-16 19:23 +0200
            Re: True == 1 weirdness Grant Edwards <invalid@invalid.invalid> - 2015-09-16 17:27 +0000
              Re: True == 1 weirdness Emile van Sebille <emile@fenx.com> - 2015-09-16 10:41 -0700
              Re: True == 1 weirdness Steven D'Aprano <steve@pearwood.info> - 2015-09-17 03:42 +1000
                Re: True == 1 weirdness Grant Edwards <invalid@invalid.invalid> - 2015-09-16 17:44 +0000
                  Re: True == 1 weirdness Random832 <random832@fastmail.com> - 2015-09-16 13:55 -0400
                  Re: True == 1 weirdness Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-16 11:55 -0600
                  Re: True == 1 weirdness Steven D'Aprano <steve@pearwood.info> - 2015-09-17 11:16 +1000
              Re: True == 1 weirdness Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-16 21:22 +0100
          Re: True == 1 weirdness Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-16 21:17 +0100
        Re: True == 1 weirdness Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-09-17 18:24 +1200
          Re: True == 1 weirdness Jussi Piitulainen <harvesting@makes.email.invalid> - 2015-09-17 10:06 +0300
            Re: True == 1 weirdness Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-17 12:49 -0600
              Re: True == 1 weirdness Jussi Piitulainen <harvesting@makes.email.invalid> - 2015-09-17 23:24 +0300
                Re: True == 1 weirdness Random832 <random832@fastmail.com> - 2015-09-17 17:26 -0400
                  Re: True == 1 weirdness Marko Rauhamaa <marko@pacujo.net> - 2015-09-18 00:38 +0300
                    Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-17 23:49 +0200
                    Re: True == 1 weirdness Chris Angelico <rosuav@gmail.com> - 2015-09-18 12:03 +1000
                  Re: True == 1 weirdness Jussi Piitulainen <harvesting@makes.email.invalid> - 2015-09-18 10:10 +0300
                  Re: True == 1 weirdness Steven D'Aprano <steve@pearwood.info> - 2015-09-18 22:30 +1000
            Re: True == 1 weirdness Chris Angelico <rosuav@gmail.com> - 2015-09-18 04:57 +1000
              Re: True == 1 weirdness Jussi Piitulainen <harvesting@makes.email.invalid> - 2015-09-17 23:44 +0300
      Re: True == 1 weirdness Tim Chase <python.list@tim.thechases.com> - 2015-09-16 09:38 -0500
      Re: True == 1 weirdness Random832 <random832@fastmail.com> - 2015-09-16 11:40 -0400
        Re: True == 1 weirdness Steven D'Aprano <steve@pearwood.info> - 2015-09-17 03:33 +1000
          Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-16 19:41 +0200
            Re: True == 1 weirdness Steven D'Aprano <steve@pearwood.info> - 2015-09-17 11:22 +1000
          Re: True == 1 weirdness Random832 <random832@fastmail.com> - 2015-09-16 13:47 -0400
            Re: True == 1 weirdness Grant Edwards <invalid@invalid.invalid> - 2015-09-16 17:52 +0000
            Re: True == 1 weirdness Steven D'Aprano <steve@pearwood.info> - 2015-09-17 11:25 +1000
              Re: True == 1 weirdness Random832 <random832@fastmail.com> - 2015-09-17 02:10 -0400
                Re: True == 1 weirdness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-09-17 12:29 +0000
          Re: True == 1 weirdness Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-16 21:38 +0100
          Re: True == 1 weirdness Random832 <random832@fastmail.com> - 2015-09-16 16:55 -0400
          Re: True == 1 weirdness "Sven R. Kunze" <srkunze@mail.de> - 2015-09-16 23:03 +0200
      Re: True == 1 weirdness jmp <jeanmichel@sequans.com> - 2015-09-21 14:01 +0200
    Re: True == 1 weirdness jmp <jeanmichel@sequans.com> - 2015-09-16 15:08 +0200
      Re: True == 1 weirdness "Blake T. Garretson" <blake.garretson@gmail.com> - 2015-09-16 06:17 -0700
    Re: True == 1 weirdness Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-16 09:28 -0400
    Re: True == 1 weirdness Chris Angelico <rosuav@gmail.com> - 2015-09-17 00:57 +1000

Page 5 of 5 — ← Prev page 1 2 3 4 [5]


#96675

Fromjmp <jeanmichel@sequans.com>
Date2015-09-16 15:08 +0200
Message-ID<mailman.633.1442408922.8327.python-list@python.org>
In reply to#96672
On 09/16/2015 02:16 PM, Blake T. Garretson wrote:
>>>> 1 in {1:1} == 1   #test2

>The second test yield False, because True does not equal 1, apparently.  Fair enough.

No, it yields False because {1:1} == 1 is false. Test 2 looks actually like

(1 in {1:1}) and ({1:1} == 1).

Which in your example does not make any sense but think of this one:

x = 5
3 < x < 10

JM

[toc] | [prev] | [next] | [standalone]


#96678

From"Blake T. Garretson" <blake.garretson@gmail.com>
Date2015-09-16 06:17 -0700
Message-ID<3c5c897f-5351-4acc-8024-f3cc43431e19@googlegroups.com>
In reply to#96675
On Wednesday, September 16, 2015 at 9:08:54 AM UTC-4, jmp wrote:
> x = 5
> 3 < x < 10

That's a great example.  I use this case all the time and didn't think to apply the same principal to the in/== case.  I assumed that "in" was evaluated first, and then the == comparison was made.  Thanks!

[toc] | [prev] | [next] | [standalone]


#96679

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2015-09-16 09:28 -0400
Message-ID<mailman.635.1442410144.8327.python-list@python.org>
In reply to#96672
On Wed, 16 Sep 2015 05:16:21 -0700 (PDT), "Blake T. Garretson"
<blake.garretson@gmail.com> declaimed the following:

>I am maintaining some old code where the programmer used 1 for True because booleans hadn't been added to Python yet.  I'm getting some weird behaviour, so I created some simple tests to illustrate my issue.
>
>>>> 1 in {1:1}        #test1
>True
>>>> 1 in {1:1} == 1   #test2
>False
>>>> (1 in {1:1}) == 1 #test3
>True
>>>> 1 in ({1:1} == 1) #test4
>Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>TypeError: argument of type 'bool' is not iterable
>>>>
>
>You can see that in the first test we get True as expected.  The second test yield False, because True does not equal 1, apparently.  Fair enough.  But then the third test yields True.  Weird.  Okay, so maybe it was evaluating the right side first?  So I put the parens over to the right and it fails, so that wasn't it.  So why do the second and third test differ?

	Most likely, you've run into chained conditionals...

	a < x < b

is interpreted as

	a < x AND x < b

so...

	1 in {1:1} == 1

becomes

	1 in {1:1} AND {1:1} == 1

	True AND False
	False

	I'll admit, I didn't think the "in" operation took part in chaining.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#96684

FromChris Angelico <rosuav@gmail.com>
Date2015-09-17 00:57 +1000
Message-ID<mailman.645.1442415437.8327.python-list@python.org>
In reply to#96672
On Wed, Sep 16, 2015 at 11:45 PM, Watson, Paul <pwatson@phs.org> wrote:
> In terms of operator precedence, is "==" evaluated before "in"?

No, they're at the same precedence level. Within that, all comparison
operators are evaluated left-to-right, with the chaining that was
described earlier.

ChrisA

[toc] | [prev] | [standalone]


Page 5 of 5 — ← Prev page 1 2 3 4 [5]

Back to top | Article view | comp.lang.python


csiph-web