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


Groups > comp.lang.python > #53938

Re: Dealing with Lists

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.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; 'example:': 0.03; 'output': 0.05; 'represents': 0.05; 'level,': 0.07; 'nested': 0.07; 'logic': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spaces': 0.09; 'def': 0.12; '*always*': 0.16; 'comma': 0.16; 'formatted': 0.16; 'indent': 0.16; 'item:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'requested.': 0.16; 'stan': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'seems': 0.21; '(the': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'gives': 0.31; '-0700,': 0.31; "d'aprano": 0.31; 'grouping': 0.31; 'sep': 0.31; 'steven': 0.31; 'way?': 0.31; 'figure': 0.32; 'another': 0.32; 'problem': 0.35; 'subject:with': 0.35; 'but': 0.35; 'next': 0.36; 'charset:us-ascii': 0.36; 'so,': 0.37; 'list': 0.37; 'level': 0.37; 'follows:': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'how': 0.40; 'first': 0.61; 'said:': 0.68; 'greetings': 0.72; 'all!': 0.84; 'legs': 0.84; 'subject:Lists': 0.91; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: Dealing with Lists
Date Wed, 11 Sep 2013 02:24:44 +0000 (UTC)
References <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> <522fd1ee$0$29988$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 174.32.174.36
User-Agent XPN/1.2.6 (Street Spirit ; Linux)
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.231.1378866311.5461.python-list@python.org> (permalink)
Lines 60
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1378866311 news.xs4all.nl 15923 [2001:888:2000:d::a6]:54130
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53938

Show key headers only | View raw


On 10/9/2013 22:14, Steven D'Aprano wrote:

> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote:
>
>> Greetings to all!
>> 
>> i ran into a little logic problem and trying to figure it out.
>> 
>> my case is as follows:
>> 
>> i have a list of items each item represents a Group
>> i need to create a set of nested groups,
>> so, for example:
>> 
>> myGroups = ["head", "neck", "arms", "legs"]
>
>
> What is the rule for grouping these items? Below, you suggest:
>
> head encloses neck
> neck encloses arms
> arms encloses legs
>
> which seems rather strange. But if it is *always* the case that each item 
> encloses the next item:
>
> def print_nested_list(alist):
>     spaces = ' '*4
>     for level, item in enumerate(alist):
>         if level != 0:
>             indent = spaces*(level-1) + '  '
>             print (indent + '|_>'),  # note comma
>         print item
>
>
> which gives us this:
>
> py> print_nested_list(['head', 'neck', 'arms', 'legs'])
> head
>   |_> neck
>       |_> arms
>           |_> legs
>
>
> as requested.
>
>

Very nice.  But what I want to know is how did you know that Stan (the
OP) wanted his printed output to be formatted that way?  He said:

>>>>> i need to create a set of nested groups,
and
>>>>> store each of the first elements of a par, so I can reference to them as to a parent of another group.


-- 
DaveA

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


Thread

Dealing with Lists stas poritskiy <stascrash@gmail.com> - 2013-09-10 14:08 -0700
  Re: Dealing with Lists stas poritskiy <stascrash@gmail.com> - 2013-09-10 14:10 -0700
  Re: Dealing with Lists matt.komyanek@gmail.com - 2013-09-10 14:31 -0700
  Re: Dealing with Lists Dave Angel <davea@davea.name> - 2013-09-10 21:51 +0000
    Re: Dealing with Lists stas poritskiy <stascrash@gmail.com> - 2013-09-10 15:11 -0700
      Re: Dealing with Lists Roy Smith <roy@panix.com> - 2013-09-10 18:30 -0400
      Re: Dealing with Lists Dave Angel <davea@davea.name> - 2013-09-10 22:32 +0000
  Re: Dealing with Lists Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-11 02:14 +0000
    Re: Dealing with Lists Dave Angel <davea@davea.name> - 2013-09-11 02:24 +0000
      Re: Dealing with Lists Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-11 03:13 +0000
        Re: Dealing with Lists stas poritskiy <stascrash@gmail.com> - 2013-09-10 20:44 -0700
        Re: Dealing with Lists stas poritskiy <stascrash@gmail.com> - 2013-09-10 20:52 -0700
          Re: Dealing with Lists stas poritskiy <stascrash@gmail.com> - 2013-09-11 07:47 -0700
            Re: Dealing with Lists stas poritskiy <stascrash@gmail.com> - 2013-09-11 07:57 -0700
              Re: Dealing with Lists Peter Otten <__peter__@web.de> - 2013-09-11 18:17 +0200

csiph-web