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: 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 Subject: Re: Trees Date: Tue, 20 Jan 2015 21:19:07 -0500 References: 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: 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: 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 On 1/20/2015 4:47 PM, Mario wrote: > In article , > 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