Python export addon: assign faces to vertex groups Hi I am making an export code for a custom model format.

I need the mesh to be divided in parts, each part has to be made of triangle faces with their vertices assigned to 7 vertex groups.

The following code is supposed to store the faces ingroups, once a group of faces has more than 7 vertex groups, it should go to the next group.
Every vertex has only ONE vertex group assigned (one bone) for simplicity.

The problen is, this code only works for the first group, then it sets split = 1, and that's it... split is never 2. So I get the first group with its 7 vertex groups, and the second group with the rest (more than 7).

I'm new in python, I am surelly making some big mistake here, thanks a lot!

for face in obj.data.polygons:

    #assign group to face
    for vert in face.vertices:
        for item in obj.data.vertices[vert].groups:
            if split == 0:
                if item.group not in VGROUP[0]:
                    VGROUP[0].append(item.group)
            if split == 1:
                if item.group not in VGROUP[1]:
                    VGROUP[1].append(item.group)
            if split == 2:
                if item.group not in VGROUP[2]:
                    VGROUP[2].append(item.group)
            if split == 3:
                if item.group not in VGROUP[3]:
                    VGROUP[3].append(item.group)
    if split == 0 and len(VGROUP[0]) == 7: 
        split = 1
        file.write('Hey, vgroup split 1!\n')
    if split == 1 and len(VGROUP[1]) == 7: 
        split = 2
        file.write('Hey, vgroup split 2!\n')
    if split == 2 and len(VGROUP[2]) == 7: 
        split = 3
        file.write('Hey, vgroup split 3!\n')

    for vert in face.vertices: #store vertices in DATA
        DATA[split].append(obj.data.vertices[vert].co[0])
                    #uv, normal, etc...


update... edit

Ok I'll try to explain in other way.  

I want to divide a list in parts, so that every part contains only x different items.

My code tries to take a list, read it item by item, and when it has found x different items, it stores them in another list, and continues reading the original one. 

For example:

a = [0,1,0,1,2,1,0,1,3,0,2,2,4,2,2,6,2,1,6,3,2]

for item in a:

#Take a, read it, if the value is new in r0, store it in r0 until r0 has 3 values:
if split == 0: 
    if item not in r0:
        r0.append(item)
if len(r0) &gt; 2:
    split = 1

#Continue reading a, if the value is new in r1, store it in r1 until r1 has 3 values:
if split == 1: 
    if item not in r0:
        r0.append(item)
if len(r1) &gt; 2:
    split = 2

#Continue reading a, if the value is new in r2, store it in r2 until r2 has 3 values:
if split == 2: 
    if item not in r0:
        r0.append(item)
if len(r2) &gt; 2:
    split = 3
#and so on


The results should be:

r0 = [0,1,2]
r1 = [1,0,3]
r2 = [0,2,4]


But the results are very different:


r0 = [0,1,2] #Ok this one worked !!
r1 = [1,2,2,1,0,3,4,6] #Mmm.. What?
r2 = [0,1,3,2,4,6] #completely lost


I export vertices from a mesh, each vertex has one bone assigned to it (or one vertex group), so i get a list containing all the vertices with their vertex group, then i want to split the list in parts containing 7 vertex groups.

Thanks again
Well I spent days with this, and suddenly I got it, thanks anyway.

This cuts a ist in parts, for example, my vertices list, without repeating items in every part. 
I had to use a while, for loops are not working exactly how I thought in python.

split = 0
r0 = []
r1 = []
r2 = []
#and so on...

a = [0,1,0,1,2,1,0,1,3,0,2,2,4,2,2,6,2,1,6,3,2]
i = 0

while i &lt; len(a):
if split == 0: 
    if a[i] not in r0:
        r0.append(a[i])
    if len(r0) == 3:
        split = 1
        i = i + 1

if split == 1: 
    if a[i] not in r1:
        r1.append(a[i])
    if len(r1) == 3:
        split = 2
        i = i + 1

if split == 2: 
    if a[i] not in r2:
        r2.append(a[i])
    if len(r2) == 3:
        split = 3
        i = i + 1

i = i + 1


#the results are: 
r0 = [0,1,2]
r1 = [1,0,3]
r2 = [0,2,4]