Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'mrab': 0.05; 'read-only': 0.09; 'python': 0.11; 'conformance': 0.16; 'container.': 0.16; 'containers': 0.16; 'docstring': 0.16; 'integers.': 0.16; 'iterating': 0.16; 'length.': 0.16; 'sequence.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '(the': 0.22; 'feb': 0.22; '>>>': 0.22; 'comparing': 0.24; 'instance,': 0.24; 'string,': 0.24; 'looks': 0.24; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; 'returned': 0.30; 'message- id:@mail.gmail.com': 0.30; 'container': 0.31; 'so-called': 0.31; 'view.': 0.31; 'another': 0.32; 'actual': 0.34; 'subject:the': 0.34; 'agree': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'definition': 0.35; 'objects': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'object,': 0.36; 'view,': 0.36; 'virtual': 0.37; 'so,': 0.37; 'list': 0.37; 'received:209': 0.37; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'most': 0.60; 'range': 0.61; 'kind': 0.63; 'here': 0.66; '2015': 0.84; 'approach.': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=QgWfwoQmdMykPkZ0vbHMWGOBEdf5ZCSCkLNQyfnmdW8=; b=SX91QztAk1AUzw9NOIF03wvgWEFEcWYMPdaC62ds9lJrI8Bc2gzNuPn/Xsj0/GTSA3 t/7CDTIakxnMnChntEBpzfcsO7SjZ3ZSLclbnHAFcH1iVk9duihX8v5haYmJ45lDFupP lXFr+lXYahXQsCP17Z0Xd7uuAb3TkdKzxJy7YYwrQp5LG0uY97ulOE9bgxyAdhqyd1U0 9fpA7Eq8vrmQDkgqoQ/LcqOOUu8WxSQ8vecSVsmrs5GkYjYvBe9jNlV6aSiyLWi7vP1X WlF7jodknn30e5ReT7KJ/qBhs92ghzbkuGpQw13txqBhp/NTus/7yhtQExZJihedjmcb XVZg== X-Received: by 10.66.120.47 with SMTP id kz15mr1017379pab.35.1424285497144; Wed, 18 Feb 2015 10:51:37 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <54E4D418.5030109@mrabarnett.plus.com> References: <71e8463f-2a60-4fb0-a5b7-0ca7cd3efece@googlegroups.com> <472c49ae-c2ce-4eda-b922-f16613722e31@googlegroups.com> <1d87da9c-ef64-4bd2-9179-e2aad908a9d0@googlegroups.com> <54E4D418.5030109@mrabarnett.plus.com> From: Ian Kelly Date: Wed, 18 Feb 2015 11:50:56 -0700 Subject: Re: What the Pythons docs means by "container" ? To: Python Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424285506 news.xs4all.nl 2915 [2001:888:2000:d::a6]:41369 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85808 On Wed, Feb 18, 2015 at 11:04 AM, MRAB wrote: > On 2015-02-18 02:14, candide wrote: >> >> Le mercredi 18 f=C3=A9vrier 2015 01:50:16 UTC+1, Chris Angelico a =C3=A9= crit : >> >>> So, what's a container? It's a thing that you put other objects >>> into. >> >> >> I agree with this approach. The important point to consider here is >> the last word in your definition : "into". There is the container and >> there is the content (the objects into). The so-called built-in >> containers (list, string, etc) are in conformance with this view. >> Now, regarding a range object as a container disagrees completely >> with the definition given in the PLR : there is no contents and hence >> there is no container. For instance, range(10**6) doesn't hold any >> kind of object, there are no reference to the int objects 0, 1, 2, >> ... As the range's docstring explains, range returns a VIRTUAL >> sequence. >> > It's a virtual, read-only container that contains integers. > > Try comparing range(10) with tuple(range(10)). Both contain integers. > Both have a length. Both can be indexed. Another way to look at range is as an optimization of the range from Python 2, which returned an actual list of integers. Most callers are only interested in iterating over the container and don't have to be concerned whether the result is actually a list or just something that looks enough like one for their purposes. From that point of view, a range object is still a container.