On Mon, Nov 8, 2021 at 1:43 PM Ethan Furman <et...@stoneleaf.us> wrote:

> When is an empty container contained by a non-empty container?
>
> For example:
>
> {} in {1:'a', 'b':2}   <-- TypeError because of hashability
>

(You accidentally wrote a square close bracket, but I know you meant a
curly close brace. :-}


> set() in {1, 2, 'a', 'b'}  <-- ditto
>
> [] in ['a', 'b', 1, 2]  <-- False
>

These examples make me think that you're somehow confused between "is an
element of" (which for Python sets is spelled using 'in', and has a similar
spelling and meaning for dicts and sequences), and "is a subset of" (which
we spell as '<=' for sets, and don't support for other types).


> '' in 'a1b2'  <-- True
>

As Steven explained this is a different case again (subsequence, not subset
or element).

SomeFlag.nothing in SomeFlag.something  <--  ???
>

This case definitely sounds to me like there is that confusion. Assuming
'nothing' is zero, it is not an *element*, so it should not be tested with
'in'. The 'in' operator should only be used if the left operator represents
exactly one flag set.

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/2VTVWAWS3A5KTNOLIAOXWEZEHRGUHOLV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to