Dealing with Lists

stas poritskiy stascrash at gmail.com
Tue Sep 10 17:08:45 EDT 2013


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