Re: Test 0 and false since false is 0

2017-07-12 Thread Terry Reedy
On 7/12/2017 7:35 AM, Rhodri James wrote: On 12/07/17 03:29, Stefan Ram wrote: Grant Edwards writes: False is required to be a singleton. »singleton« usually means »the sole object of its class«. »Ensure a class only has one instance, and provide a

Re: Test 0 and false since false is 0

2017-07-12 Thread Rhodri James
On 12/07/17 03:29, Stefan Ram wrote: Grant Edwards writes: False is required to be a singleton. »singleton« usually means »the sole object of its class«. »Ensure a class only has one instance, and provide a global point of access to it.« - Gamma

Re: Test 0 and false since false is 0

2017-07-11 Thread Steve D'Aprano
On Tue, 11 Jul 2017 11:16 pm, Albert-Jan Roskam wrote: > >>> False == 0 > True > >>> False is 0 > False > > > => Just wondering: Is this 'is' test depending on an implementation detail > of cPython (small ints, I forgot how small 0-255 maybe, are singletons)? No. But the test 0 is 0 will

Re: Test 0 and false since false is 0

2017-07-11 Thread Grant Edwards
On 2017-07-11, Albert-Jan Roskam <sjeik_ap...@hotmail.com> wrote: > From: Python-list <python-list-bounces+sjeik_appie=hotmail@python.org> on > behalf of Dan Sommers <d...@tombstonezero.net> > Sent: Friday, July 7, 2017 2:46 AM > To: python-list@python.org &

Re: Test 0 and false since false is 0

2017-07-11 Thread Rhodri James
On 11/07/17 14:16, Albert-Jan Roskam wrote: From: Python-list <python-list-bounces+sjeik_appie=hotmail@python.org> on behalf of Dan Sommers <d...@tombstonezero.net> Sent: Friday, July 7, 2017 2:46 AM To: python-list@python.org Subject: Re: Test 0 and false since false is 0

Re: Test 0 and false since false is 0

2017-07-11 Thread Albert-Jan Roskam
From: Python-list <python-list-bounces+sjeik_appie=hotmail@python.org> on behalf of Dan Sommers <d...@tombstonezero.net> Sent: Friday, July 7, 2017 2:46 AM To: python-list@python.org Subject: Re: Test 0 and false since false is 0   On Thu, 06 Jul 2017 19:29:00 -0700, Sayth R

Re: Test 0 and false since false is 0

2017-07-10 Thread Grant Edwards
On 2017-07-09, Paul D. DeRocco wrote: >> From: Sayth Renshaw >> >> I have been reading this solution >> > >>> after = sorted(before, key=lambda x: x == 0 and type(x) == int) >> >> it is really good, however I don't understand it enough to >> reimplement something like

RE: Test 0 and false since false is 0

2017-07-08 Thread Paul D. DeRocco
> From: Sayth Renshaw > > I have been reading this solution > > >>> after = sorted(before, key=lambda x: x == 0 and type(x) == int) > > it is really good, however I don't understand it enough to > reimplement something like that myself yet. > > Though I can that lambda tests for 0 that is

Re: Test 0 and false since false is 0

2017-07-08 Thread Sayth Renshaw
> Another option is to test for type(value) == int: > > >>> before = ["a",0,0,"b",None,"c","d",0,1,False,0,1,0,3,[],0,1,9,0,0, > {},0,0,9] > >>> wanted = ["a","b",None,"c","d",1,False,1,3,[],1,9, > {},9,0,0,0,0,0,0,0,0,0,0] > >>> after = sorted(before, key=lambda x: x == 0 and type(x) == int) >

Re: Test 0 and false since false is 0

2017-07-07 Thread Peter Otten
Nathan Ernst wrote: > On Fri, Jul 7, 2017 at 2:04 AM, Peter Otten <__pete...@web.de> wrote: >> >>> sorted([0.0, 0, False, [], "x"], key=lambda x: x == 0 and type(x) == >> int) >> [0.0, False, [], 'x', 0] > You'd be better off using the builtin "isinstance" function, e.g.: > isinstance(x, int).

Re: Test 0 and false since false is 0

2017-07-07 Thread Nathan Ernst
You'd be better off using the builtin "isinstance" function, e.g.: isinstance(x, int). This also has the added benefit of working nicely with inheritance (isinstance returns true if the actual type is derived from the classinfo passed as the second argument). See

Re: Test 0 and false since false is 0

2017-07-07 Thread Grant Edwards
On 2017-07-07, Stefan Ram wrote: > Sayth Renshaw writes: >>I have tried or conditions of v == False etc but then the 0's >>being false also aren't moved. How can you check this at >>once? > > »The Boolean type is a subtype of the integer

Re: Test 0 and false since false is 0

2017-07-07 Thread zhenghao li
you can use the "is" for identity test. l1 = [v for v in array if not v is 0] l2 = [v for v in array if v is 0] On Jul 6, 2017, at 10:31 PM, Sayth Renshaw > wrote: I was trying to solve a problem and cannot determine how to filter 0's but

RE: Test 0 and false since false is 0

2017-07-07 Thread Paul D. DeRocco
> From: Dan Sommers > > > On Thu, 06 Jul 2017 19:29:00 -0700, Sayth Renshaw wrote: > > > > I have tried or conditions of v == False etc but then the 0's being > > false also aren't moved. How can you check this at once? > > Maybe this will help: > > Python 3.5.3+ (default, Jun 7 2017,

Re: Test 0 and false since false is 0

2017-07-07 Thread Peter Otten
Sayth Renshaw wrote: > I was trying to solve a problem and cannot determine how to filter 0's but > not false. > > Given a list like this > ["a",0,0,"b",None,"c","d",0,1,False,0,1,0,3,[],0,1,9,0,0,{},0,0,9] > > I want to be able to return this list >

Re: Test 0 and false since false is 0

2017-07-06 Thread Rick Johnson
On Thursday, July 6, 2017 at 9:57:43 PM UTC-5, Skip Montanaro wrote: > I was trying to solve a problem and cannot determine how to filter 0's but > not false. > > > I'm typing on my phone so can't paste a session [...] I have not tried any for myself, but there are a few Python installations

Re: Test 0 and false since false is 0

2017-07-06 Thread Rick Johnson
On Thursday, July 6, 2017 at 10:00:36 PM UTC-5, Sayth Renshaw wrote: > Is there an "is not" method that's not != so I can check is not false. Maybe. Or maybe /not/. :-P" One way to find out would be to fire up your python interpretor, and do some interactive testing. Here, allow me to cinge my

Re: Test 0 and false since false is 0

2017-07-06 Thread Sayth Renshaw
On Friday, 7 July 2017 12:46:51 UTC+10, Rick Johnson wrote: > On Thursday, July 6, 2017 at 9:29:29 PM UTC-5, Sayth Renshaw wrote: > > I was trying to solve a problem and cannot determine how to filter 0's but > > not false. > > > > Given a list like this > >

Re: Test 0 and false since false is 0

2017-07-06 Thread Dan Sommers
On Fri, 07 Jul 2017 02:48:45 +, Stefan Ram wrote: def isfalse( x ): > ... return x == 0 and str( type( x )) == "" > ... > Don't depend on string representations of objects, unless you know what you're doing. Do this instead: def isfalse(x): return x == 0 and type(x) is

Re: Test 0 and false since false is 0

2017-07-06 Thread Skip Montanaro
I was trying to solve a problem and cannot determine how to filter 0's but not false. I'm typing on my phone so can't paste a session, so I will attempt to apply the Socratic method, and ask: Do you understand why your attempts have failed so far? In what way are False and 0 the same? In what

Re: Test 0 and false since false is 0

2017-07-06 Thread Dan Sommers
On Thu, 06 Jul 2017 19:29:00 -0700, Sayth Renshaw wrote: > I have tried or conditions of v == False etc but then the 0's being > false also aren't moved. How can you check this at once? Maybe this will help: Python 3.5.3+ (default, Jun 7 2017, 23:23:48) [GCC 6.3.0 20170516] on linux

Re: Test 0 and false since false is 0

2017-07-06 Thread Rick Johnson
On Thursday, July 6, 2017 at 9:29:29 PM UTC-5, Sayth Renshaw wrote: > I was trying to solve a problem and cannot determine how to filter 0's but > not false. > > Given a list like this > ["a",0,0,"b",None,"c","d",0,1,False,0,1,0,3,[],0,1,9,0,0,{},0,0,9] > > I want to be able to return this list

Test 0 and false since false is 0

2017-07-06 Thread Sayth Renshaw
I was trying to solve a problem and cannot determine how to filter 0's but not false. Given a list like this ["a",0,0,"b",None,"c","d",0,1,False,0,1,0,3,[],0,1,9,0,0,{},0,0,9] I want to be able to return this list ["a","b",None,"c","d",1,False,1,3,[],1,9,{},9,0,0,0,0,0,0,0,0,0,0] However if I