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


Groups > comp.lang.python > #84100

Re: Trees

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'resulting': 0.04; 'third-party': 0.04; 'interpreter': 0.05; 'tree': 0.05; 'nested': 0.07; '[1,': 0.09; 'builtin': 0.09; 'instance.': 0.09; 'objects,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'restriction': 0.09; 'trees': 0.09; 'python': 0.11; 'jan': 0.12; 'posted': 0.15; 'collections': 0.16; 'collections.': 0.16; 'cyclic': 0.16; 'hierachical': 0.16; 'illustrates': 0.16; 'indirectly': 0.16; 'infinitely': 0.16; 'list"': 0.16; 'measures': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'says...': 0.16; 'unneeded': 0.16; 'words.': 0.16; 'demonstrate': 0.16; 'wrote:': 0.18; "python's": 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'alternate': 0.24; '(or': 0.24; 'question': 0.24; 'suggested': 0.26; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'point': 0.28; '[1]': 0.29; 'commonly': 0.31; 'libraries': 0.31; 'languages': 0.32; 'quite': 0.32; 'limitation': 0.33; 'display': 0.35; 'common': 0.35; 'but': 0.35; 'there': 0.35; 'limitations': 0.36; 'raising': 0.36; 'sequence': 0.36; "didn't": 0.36; 'useful': 0.36; 'turn': 0.37; 'list': 0.37; 'implement': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'structure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'most': 0.60; 'simple': 0.61; 'email addr:gmail.com': 0.63; 'more': 0.64; 'account': 0.65; 'therefore': 0.72; 'overcome': 0.74; 'special': 0.74; 'article': 0.77; 'yourself': 0.78; 'directed': 0.83; 'received:fios.verizon.net': 0.84; 'typically,': 0.84; 'vain': 0.84; '"how': 0.91; 'received:108': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Trees
Date Tue, 20 Jan 2015 21:19:07 -0500
References <CAG=hEY1L-39EmuWpdEh_n-BNfs=qG9nL=MrMT0ar72yGBrkoUA@mail.gmail.com> <mailman.17884.1421734095.18130.python-list@python.org> <d34dbfbe-fe82-47dc-8bc3-c8773e2b70dd@googlegroups.com> <MPG.2f28eb55d73ef68c989680@nntp.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-108-16-203-145.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
In-Reply-To <MPG.2f28eb55d73ef68c989680@nntp.aioe.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.17902.1421806760.18130.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1421806760 news.xs4all.nl 2883 [2001:888:2000:d::a6]:41916
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:84100

Show key headers only | View raw


On 1/20/2015 4:47 PM, Mario wrote:
> In article <d34dbfbe-fe82-47dc-8bc3-c8773e2b70dd@googlegroups.com>,
> rustompmody@gmail.com says...
>>
>> Yeah python has trees alright.
>>
>> Heres' some simple tree-code
>
> Didn't you just demonstrate that Python has no trees and instead you
> have to implement them yourself (or use a third-party implementation)?
>
> I don't know what's the point of all this vain and misleading play with
> words.

It is not play with words. A tree is a recursive - nested - hierachical 
data structure with the restriction of no cycles or alternate pathways. 
  Python collections whose members are general objects, including 
collections, can be nested.  The resulting structures *are* tree 
structures, if not more general directed graphs.  They are quite 
commonly used in Python.

The common question -- "How do I flatten a list" -- is asking "How to I 
turn a list from a tree (or DAG, but not a cyclic graph*) into a 
sequence of leaf objects".  The question illustrates what is missing - 
builtin functions or methods for nested collections.  I already 
suggested that there *might* be a useful addition in this direction.

* A Python interpreter needs to take special measures to even display an 
infinitely recursive list without raising or even segfaulting.  Most 
posted 'flatten' functions do not account for this possibility.

 >>> l = [1]
 >>> l.append(l)
 >>> l
[1, [...]]


 > Not only most languages don't implement trees in their standard
> libraries

Typically, built-in collection type C has members of type M that does 
not include type C.  Therefore a C instance cannot (directly) contain a 
C instance.  The result is that people write a 'design pattern' to 
overcome the limitation and enable a C to indirectly include a C.  Since 
this limitations does not exist in Python's generalized collections of 
objects, the pattern is unneeded in Python.

-- 
Terry Jan Reedy

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


Thread

Re: Trees Terry Reedy <tjreedy@udel.edu> - 2015-01-20 01:08 -0500
  Re: Trees Marko Rauhamaa <marko@pacujo.net> - 2015-01-20 11:45 +0200
    Re: Trees Paul Rubin <no.email@nospam.invalid> - 2015-01-20 10:14 -0800
      Re: Trees Marko Rauhamaa <marko@pacujo.net> - 2015-01-20 22:26 +0200
    Re: Trees Stephen Hansen <me+python@ixokai.io> - 2015-01-20 23:56 -0800
      Re: Trees Marko Rauhamaa <marko@pacujo.net> - 2015-01-21 10:35 +0200
      Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-21 04:09 -0800
        Re: Trees Chris Angelico <rosuav@gmail.com> - 2015-01-21 23:35 +1100
          Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-21 07:24 -0800
        Re: Trees Tim Chase <python.list@tim.thechases.com> - 2015-01-21 06:55 -0600
        Re: Trees Chris Angelico <rosuav@gmail.com> - 2015-01-22 00:01 +1100
        Re: Trees Tim Chase <python.list@tim.thechases.com> - 2015-01-21 08:26 -0600
        Re: Trees Chris Angelico <rosuav@gmail.com> - 2015-01-22 01:31 +1100
        Re: Trees Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-22 01:47 +1100
          Re: Trees Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-21 09:15 -0700
          Re: Trees Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-21 10:27 -0700
  Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-20 05:33 -0800
    Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-20 05:51 -0800
    Re: Trees Marko Rauhamaa <marko@pacujo.net> - 2015-01-20 16:15 +0200
      Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-20 06:35 -0800
    Re: Trees Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-20 10:19 -0700
      Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-20 10:15 -0800
        Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-20 10:35 -0800
    Re: Trees Mario <marfig@gmail.com> - 2015-01-20 22:47 +0100
      Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-20 17:23 -0800
        Re: Trees Paul Rubin <no.email@nospam.invalid> - 2015-01-20 17:49 -0800
          Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-20 18:03 -0800
            Re: Trees Paul Rubin <no.email@nospam.invalid> - 2015-01-21 14:27 -0800
              Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-21 21:17 -0800
        Re: Trees Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-21 15:54 -0700
          Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-21 21:20 -0800
            Re: Trees Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-22 00:01 -0700
            Re: Trees Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-21 23:56 -0700
          Re: Trees Paul Rubin <no.email@nospam.invalid> - 2015-01-21 23:16 -0800
            Re: Trees Rustom Mody <rustompmody@gmail.com> - 2015-01-22 08:54 -0800
      Re: Trees Terry Reedy <tjreedy@udel.edu> - 2015-01-20 21:19 -0500
        Re: Trees Mario Figueiredo <marfig@gmail.com> - 2015-01-21 14:05 +0000

csiph-web