I have format a list of lists with parent_id, id and name like cascade style.
My input as follows:
category = [['id','name','parent_id'],[1, 'Root', 0],[10, 'Beans', 4],[2, 'Sub Root', 1],[3, 'Fruits', 2],[4, 'Veg', 2],[5, 'Apple', 3],[6, 'Onion', 4]]
And my excepted output follows as
out_category = [[1, 'Root', 0],[2, 'Sub Root', 1],[3, 'Fruits', 2],[4, 'Veg', 2],[5, 'Apple', 3],[6, 'Onion', 4],[10, 'Beans', 4]]
I tried so far
out_category = []
for item in category[1:]:
print item[0].split(',')
categ = item[0].split(',')
out_category.append(filter(lambda x: x[0]==categ[2],categ))
print out_category