trying to work through a list in sections

Posted by user1714887 on Stack Overflow See other posts from Stack Overflow or by user1714887
Published on 2012-12-05T04:49:46Z Indexed on 2012/12/05 5:03 UTC
Read the original article Hit count: 68

Filed under:

I have a list of lists sorted by the second value of the list (the groups). I now need to iterate through this to work on each "group" at a time. the data is [name, group, data1, data2, data3, data4]. I wasn't sure if I need a while or some other sort of loop, or maybe groupby but I've never used that. any help would be appreciated.

for i in range (int(max_group)):
    x1 = []
    x2 = []
    x3 = []
    x4 = []
    if data[i][1] == i+1:
        x1.append(data[2])
        x2.append(data[3])
        x3.append(data[4])
        x4.append(data[5])
        print x1
        print 'next' # these are just to test where we're at

© Stack Overflow or respective owner

Related posts about python