Re: Odd truth result with in and ==

2018-11-23 Thread Frank Millman
"John Pote" wrote in message news:e0a8e1bc-6e03-e42b-d6e8-d690e2d5a...@jptechnical.co.uk... I interpret the above comparison as >>> bool([1,2,3]) == bool(True) True >>> A tiny addition to what has already been said. As True is by definition a boolean, you can write this as bool([1, 2,

Re: Odd truth result with in and ==

2018-11-23 Thread Alan Bawden
Chris Angelico writes: > Or you could say "not [1,2,3] == not True", > but that's a bit less clear It's less clear in more ways than one: 3.6> not [1,2,3] == not True File "", line 1 not [1,2,3] == not True ^ SyntaxError: invalid syntax 3.6> not

Re: Odd truth result with in and ==

2018-11-23 Thread Chris Angelico
On Sat, Nov 24, 2018 at 11:28 AM John Pote wrote: > But the following I found unexpected. (Python 3.6 on a Windows 7 64 bit box) > > >>> if []: print("Truthy") > ... > >>> if [1,2,3]: print("Truthy") > ... > Truthy > >>> > > from which I concluded [] is Falsey and [1,2,3] is Truthy and the

Re: Odd truth result with in and ==

2018-11-23 Thread John Pote
On 21/11/2018 19:18, Python wrote: $ python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. 1 in [1,2,3] == True False 1 in ([1,2,3] == True) Traceback (most recent call last): File "",

Re: Odd truth result with in and ==

2018-11-23 Thread Thomas Jollans
On 2018-11-22 09:58, Chris Angelico wrote: > On Thu, Nov 22, 2018 at 7:51 PM Thomas Jollans wrote: >> >> On 21/11/2018 20:18, Python wrote: >>> $ python3 >>> Python 3.5.2 (default, Nov 23 2017, 16:37:01) >>> [GCC 5.4.0 20160609] on linux >>> Type "help", "copyright", "credits" or "license" for

Re: Odd truth result with in and ==

2018-11-22 Thread Chris Angelico
On Thu, Nov 22, 2018 at 7:51 PM Thomas Jollans wrote: > > On 21/11/2018 20:18, Python wrote: > > $ python3 > > Python 3.5.2 (default, Nov 23 2017, 16:37:01) > > [GCC 5.4.0 20160609] on linux > > Type "help", "copyright", "credits" or "license" for more information. > 1 in [1,2,3] == True > >

Re: Odd truth result with in and ==

2018-11-22 Thread Thomas Jollans
On 21/11/2018 20:18, Python wrote: > $ python3 > Python 3.5.2 (default, Nov 23 2017, 16:37:01) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. 1 in [1,2,3] == True > False 1 in ([1,2,3] == True) > Traceback (most recent call

Re: Odd truth result with in and ==

2018-11-21 Thread Dan Sommers
On 11/21/18 7:09 PM, Chris Angelico wrote: > On Thu, Nov 22, 2018 at 11:04 AM Dan Sommers > <2qdxy4rzwzuui...@potatochowder.com> wrote: >> But the second one has to do an expensive subset operation. If I think >> "is elem in both sets," then I'd never write: >> >> (elem in set1) and (set1

Re: Odd truth result with in and ==

2018-11-21 Thread Chris Angelico
On Thu, Nov 22, 2018 at 11:04 AM Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: > But the second one has to do an expensive subset operation. If I think > "is elem in both sets," then I'd never write: > > (elem in set1) and (set1 <= set2) Yes, but that doesn't mean "is elem in both

Re: Odd truth result with in and ==

2018-11-21 Thread Dan Sommers
On 11/21/18 6:45 PM, Ian Kelly wrote: > On Wed, Nov 21, 2018 at 2:53 PM Serhiy Storchaka wrote: >> >> 21.11.18 22:17, Cameron Simpson пише: >>> Can someone show me a real world, or failing that - sane looking, >>> chained comparison using "in"? >> >> s[0] == s[-1] in '\'"' >> >> Tests

Re: Odd truth result with in and ==

2018-11-21 Thread DL Neil
Serhiy, On 22/11/18 10:50, Serhiy Storchaka wrote: 21.11.18 22:17, Cameron Simpson пише: Can someone show me a real world, or failing that - sane looking, chained comparison using "in"?     s[0] == s[-1] in '\'"' Tests that string s starts and ends with a single or double quote. Am

Re: Odd truth result with in and ==

2018-11-21 Thread Ian Kelly
On Wed, Nov 21, 2018 at 2:53 PM Serhiy Storchaka wrote: > > 21.11.18 22:17, Cameron Simpson пише: > > Can someone show me a real world, or failing that - sane looking, > > chained comparison using "in"? > > s[0] == s[-1] in '\'"' > > Tests that string s starts and ends with a single or

Re: Odd truth result with in and ==

2018-11-21 Thread Serhiy Storchaka
21.11.18 22:17, Cameron Simpson пише: Can someone show me a real world, or failing that - sane looking, chained comparison using "in"? s[0] == s[-1] in '\'"' Tests that string s starts and ends with a single or double quote. It can be also used with sets: elem in set1 <= set2 --

Re: Odd truth result with in and ==

2018-11-21 Thread Chris Angelico
On Thu, Nov 22, 2018 at 8:22 AM Python wrote: > > On Thu, Nov 22, 2018 at 07:54:06AM +1100, Chris Angelico wrote: > > > if item in list == item_should_be_in_list(): > > > # "good" state, i.e. is true if item is in list and should be, or > > > isn't and shouldn't. > > > ... > > > > If I

Re: Odd truth result with in and ==

2018-11-21 Thread Python
On Thu, Nov 22, 2018 at 07:54:06AM +1100, Chris Angelico wrote: > > if item in list == item_should_be_in_list(): > > # "good" state, i.e. is true if item is in list and should be, or isn't > > and shouldn't. > > ... > > If I saw this in _any_ language, I would want it to be

Re: Odd truth result with in and ==

2018-11-21 Thread Python
On Thu, Nov 22, 2018 at 06:33:54AM +1100, Chris Angelico wrote: > On Thu, Nov 22, 2018 at 6:23 AM Python wrote: > > How is the first not equivalent to either one of the second or third? > > My expectation is it should produce the same result as the second. It > > *seems* like Python is ignoring

Re: Odd truth result with in and ==

2018-11-21 Thread Chris Angelico
On Thu, Nov 22, 2018 at 7:47 AM Python wrote: > > On Thu, Nov 22, 2018 at 07:17:52AM +1100, Cameron Simpson wrote: > > On 21Nov2018 19:40, MRAB wrote: > > >On 2018-11-21 19:18, Python wrote: > > >1 in [1,2,3] == True > > >>False > > >> > > >It's a chained comparison. It applies to '<', '<=',

Re: Odd truth result with in and ==

2018-11-21 Thread Python
On Thu, Nov 22, 2018 at 07:17:52AM +1100, Cameron Simpson wrote: > On 21Nov2018 19:40, MRAB wrote: > >On 2018-11-21 19:18, Python wrote: > >1 in [1,2,3] == True > >>False > >> > >It's a chained comparison. It applies to '<', '<=', '>', '>=', > >'==' and '!=', but also to 'in', although I've

Re: Odd truth result with in and ==

2018-11-21 Thread Cameron Simpson
On 21Nov2018 19:40, MRAB wrote: On 2018-11-21 19:18, Python wrote: 1 in [1,2,3] == True False It's a chained comparison. It applies to '<', '<=', '>', '>=', '==' and '!=', but also to 'in', although I've never seen a chained comparison using 'in' in practice. Me either. In fact, I was as

Re: Odd truth result with in and ==

2018-11-21 Thread MRAB
On 2018-11-21 19:18, Python wrote: $ python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. 1 in [1,2,3] == True False 1 in ([1,2,3] == True) Traceback (most recent call last): File "",

Re: Odd truth result with in and ==

2018-11-21 Thread Chris Angelico
On Thu, Nov 22, 2018 at 6:33 AM Python wrote: > FWIW I meant my expectation is it should be the same as #3 (I confused > the 2nd item with the second subsequent thing that it did not match) > since "in" and "==" have the same precedence, and should be evaluated > in order left to right. IOW, it

Re: Odd truth result with in and ==

2018-11-21 Thread Chris Angelico
On Thu, Nov 22, 2018 at 6:23 AM Python wrote: > > $ python3 > Python 3.5.2 (default, Nov 23 2017, 16:37:01) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> 1 in [1,2,3] == True > False > >>> 1 in ([1,2,3] == True) > Traceback (most

Re: Odd truth result with in and ==

2018-11-21 Thread Python
On Wed, Nov 21, 2018 at 01:18:22PM -0600, Python wrote: > $ python3 > Python 3.5.2 (default, Nov 23 2017, 16:37:01) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> 1 in [1,2,3] == True > False > >>> 1 in ([1,2,3] == True) > Traceback

Odd truth result with in and ==

2018-11-21 Thread Python
$ python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 1 in [1,2,3] == True False >>> 1 in ([1,2,3] == True) Traceback (most recent call last): File "", line 1, in TypeError: argument of