Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #85808

Re: What the Pythons docs means by "container" ?

References (1 earlier) <mailman.18794.1424209210.18130.python-list@python.org> <472c49ae-c2ce-4eda-b922-f16613722e31@googlegroups.com> <mailman.18798.1424220589.18130.python-list@python.org> <1d87da9c-ef64-4bd2-9179-e2aad908a9d0@googlegroups.com> <54E4D418.5030109@mrabarnett.plus.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-02-18 11:50 -0700
Subject Re: What the Pythons docs means by "container" ?
Newsgroups comp.lang.python
Message-ID <mailman.18829.1424285506.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Feb 18, 2015 at 11:04 AM, MRAB <python@mrabarnett.plus.com> wrote:
> On 2015-02-18 02:14, candide wrote:
>>
>> Le mercredi 18 février 2015 01:50:16 UTC+1, Chris Angelico a é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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What the Pythons docs means by "container" ? candide <c.candide@laposte.net> - 2015-02-17 13:21 -0800
  Re: What the Pythons docs means by "container" ? Cameron Simpson <cs@zip.com.au> - 2015-02-18 08:39 +1100
    Re: What the Pythons docs means by "container" ? candide <c.candide@laposte.net> - 2015-02-17 16:30 -0800
      Re: What the Pythons docs means by "container" ? Chris Angelico <rosuav@gmail.com> - 2015-02-18 11:49 +1100
        Re: What the Pythons docs means by "container" ? candide <pascal.ortiz@gmail.com> - 2015-02-17 18:14 -0800
          Re: What the Pythons docs means by "container" ? MRAB <python@mrabarnett.plus.com> - 2015-02-18 18:04 +0000
          Re: What the Pythons docs means by "container" ? Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-18 11:50 -0700
          Re: What the Pythons docs means by "container" ? Ethan Furman <ethan@stoneleaf.us> - 2015-02-18 11:43 -0800
          Re: What the Pythons docs means by "container" ? Terry Reedy <tjreedy@udel.edu> - 2015-02-18 15:04 -0500
            Re: What the Pythons docs means by "container" ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-19 10:03 +1100
              Re: What the Pythons docs means by "container" ? Ben Finney <ben+python@benfinney.id.au> - 2015-02-19 11:05 +1100
              Re: What the Pythons docs means by "container" ? Chris Angelico <rosuav@gmail.com> - 2015-02-19 11:33 +1100
  Re: What the Pythons docs means by "container" ? Terry Reedy <tjreedy@udel.edu> - 2015-02-17 19:54 -0500
  Re: What the Pythons docs means by "container" ? perfectican <perfectican@gmail.com> - 2015-02-19 02:59 -0800
    Re: What the Pythons docs means by "container" ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-19 11:20 +0000
  Re: What the Pythons docs means by "container" ? Rustom Mody <rustompmody@gmail.com> - 2015-02-20 03:37 -0800
    Re: What the Pythons docs means by "container" ? Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-20 11:38 -0700

csiph-web