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
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
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
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