True == 1 weirdness

Tim Chase python.list at
Wed Sep 16 16:38:51 CEST 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:

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


More information about the Python-list mailing list