Hi Steve and hi everyone else. thanks for all your replies! To clarify what i want I put together the code you wrote me Steve with a list 'array' and the result of the code below:
Python Code:
def Main():array = []array.append("A1")array.append("A2")array.append([["C3","C4"], ["C5","C6"]])array.append(['A7'])array.append(['B8', 'B9'])array.append(['A10', ['B11', 'B12', ['C13', 'C14']]])WalkList(array)def WalkList(thelist):for item in thelist:if type(item) == type(list()):print "nested List found"WalkList(item)elif item is tuple:print "Tuple"WalkList(item)else:print item
so if you run the above code it gives you:
A1
A2
C3
C4
C5
C6
A7
B8
B9
A10
B11
B12
C13
C14
So as you can see it prints out the contents of the list one by one depending on which one comes first, and if its a list then it iterates through that list until it reaches contents and not sublist.
The letter (A,B,C) infront of the contents notes the sublist 'level'. According to that I would like to find a way to sort the contents that it prints out all 'As' first, then all 'Bs' then 'Cs' etc. Then the result should be:
A1
A2
A7
A10
B8
B9
B11
B12
C3
C4
C5
C6
C13
C14
Thanks everyone for your replies, I hope i clarified my question enough !
regards,
Pav



Reply With Quote
