Dealing with Lists

matt.komyanek at gmail.com matt.komyanek at gmail.com
Tue Sep 10 17:31:18 EDT 2013


What you're asking is a Ragged Hierarchy.

On Tuesday, September 10, 2013 5:08:45 PM UTC-4, 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"]
> 
> 
> 
> i need to get them to be represented like this:
> 
> (if you can imaging a folder structure)
> 
> 
> 
> head
> 
>   |_> neck
> 
>         |_> arms
> 
>               |_>legs
> 
> 
> 
> and so on until i hit the last element.
> 
> 
> 
> what i thought would work (but don't know really how to advance here) is:
> 
> 
> 
>     def createVNTgroups(self, groupsData):
> 
>         #function recieves the LIST of group elements, INDEX0 is always the
> 
>         #MAIN-ROOT of the tree
> 
> 
> 
>         for i in range(len(groupsData)):
> 
>             print groupsData[i]
> 
>             
> 
>             for q in range(1, len(groupsData)):
> 
>                 
> 
>                 print groupsData[q]
> 
> 
> 
> could someone give me a hint?
> 
> 
> 
> thanks in advance!




More information about the Python-list mailing list