Re: 0 equals False, was Re: (unknown)

2016-03-23 Thread Terry Reedy
On 3/23/2016 4:51 AM, Peter Otten wrote: The pythonic solution is "don't do this". The == operator cannot discriminate between 0, 0.0, and False, and 0j and Fraction(0, 1) and Decimal(0) or 1, 1.0, and True and 1+0j, Fraction(1, 1) and Decimal(1) Sets and dicts are based both based on (tr

Re: 0 equals False, was Re: (unknown)

2016-03-23 Thread gst
Le mercredi 23 mars 2016 04:52:02 UTC-4, Peter Otten a écrit : > Nick Eubank wrote: > > > Hello All, > > > > > > Found an odd behavior I'd never known about today, not sure if it's a bug > > or known. Python 3.4.4 (anaconda). > > True, False, 0, 1 can all be used as dictionary keys. > > > > Bu

Re: 0 equals False, was Re: (unknown)

2016-03-23 Thread INADA Naoki
Tips: Since True == 1, sum() can count Trues. >>> def count_even(seq): ... return sum(i%2 == 0 for i in seq) >>> count_even(range(100)) 50 -- https://mail.python.org/mailman/listinfo/python-list

0 equals False, was Re: (unknown)

2016-03-23 Thread Peter Otten
Nick Eubank wrote: > Hello All, > > > Found an odd behavior I'd never known about today, not sure if it's a bug > or known. Python 3.4.4 (anaconda). This is a feature. Old versions of Python did not have True and False, so they were added in a compatible way. > True, False, 0, 1 can all be us