"in"consistency?

Terry Reedy tjreedy at udel.edu
Tue Jul 8 15:25:47 EDT 2008



castironpi wrote:

> Strings are not containers.

Library Reference/Built-in Types/Sequence Types says
"Strings contain Unicode characters."
Perhaps you have a different notion of contain/container.

I prefer 'collection' to 'container' since 'container' tends to imply an 
exclusiveness that is not true.  Byte/character sequences *are* 
different from tuples, lists, sets, dicts, etc, in the following sense: 
members of the latter collection classes must exist first before being 
added to the collection (non-exclusively).  Members of the former do 
not.  (In CPython, at least, they do not).  So I consider them to 
(reiterable) *virtual* sequence collections that can produce 
subsequences on demand,

So I partially agree with you in that byte/char sequences are a 
different sub-category.

> Another container type:
> 
> Python 3.0b1 on win32
>>>> {0} in {0,1}
> False

And similarly, (0,) not in (0,1), [0] not in [0,1], {0:None} not in 
{0:None,1:None).  These are all general manifest collection types that 
can contain any Python object, and which could contain a sub-collection 
even if they do not.

Terry Jan Reedy




More information about the Python-list mailing list