True == 1 weirdness
Tim Chase
python.list at tim.thechases.com
Wed Sep 16 10:38:51 EDT 2015
On 2015-09-16 10:03, Random832 wrote:
> Do chained "in" comparisons ever really make sense, even when
> they're all the same type?
>
> I mean, I suppose 1 in (1, 2) in ((1, 2), (3, 4)) is technically
> true, but how useful is it really?
I could concoct a "useful" example where "in" is involved in a
chain, something like
set_of_valid_ids = generate_valid_ids_maybe_negative()
if 0 < i in set_of_valid_ids:
do_something(i)
This would unpack as "if 0 > i and i in set_of_valid_ids".
However the "useful"ness of it doesn't outweigh the horrible
readability IMHO. So I'd never actually *use* this, even if it might
be "useful".
-tkc
More information about the Python-list
mailing list