What the Pythons docs means by "container" ?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Feb 18 18:03:47 EST 2015


Terry Reedy wrote:

> On 2/18/2015 2:43 PM, Ethan Furman wrote:
> 
>> Whether a "contained" object exists before it is accessed is irrelevant,
>> is an implementation detail, and is a level of optimization.
> 
> Is in not irrelevant in that virtual collections can be infinite.

Hmmm. I'm not sure I believe that. Can you enumerate all of the items and
see if there actually is an infinite number of them? I'll wait... 

*wink*

But seriously... Ethan's comment shouldn't be interpreted as meaning that
virtual containers are exactly the same as concrete ones. Ethan's comment
should be understand in terms that whether something is a container or not
is *not* connected to whether it is a concrete data structure like a list
or an array, or a virtual/lazy/on-demand data structure like (x)range.

In Python ABC terms, I believe that the, or at least a, defining
characteristic of containers is that they implement the "in" operator. If
there is some value X for which `X in OBJ` succeeds, then OBJ may be a
container.




-- 
Steven




More information about the Python-list mailing list