nested grouping in Python
HI All
Is there a way of nested grouping in python
I wish to format a file as given below
Input File:
Item: 1
sub1
A,10,x,5
B,345,v,7
C,67,u,9
sub2
A,09,9,.09
B,65,3..34
C,8,8,1
Item: 2
sub1
A,10,x,5
B,345,v,7
C,67,u,9
sub2
A,09,9,.23
B,65,3..2
C,8,8,.5
Item: 3
sub1
A,10,x,5
B,345,v,7
C,67,u,9
sub2
A,09,9,.5
B,65,3..4
C,8,8,6
group by Item and then group by sub so that I retain the sub1 and append the last element in sub2 to the output
Required output:
Item: 1
A,10,x,5,.09
B,345,v,7,.34
C,67,u,9,1
Item: 2
A,10,x,5,.23
B,345,v,7,2
C,67,u,9,.5
Item: 3
A,10,x,5,.5
B,345,v,7,.4
C,67,u,9,6
Any suggestion will be immensely appreciated
Thanks
Abid