Python list operation – merge adjacent cubes into minimum number of shapes

I am hoping to find a way to make the process a lot faster. The lists are made of rows of 6 numbers, i.e. [[float] * 6, …]. The intent is to pass a list of cube co-ordinates (only two 3D co-ordinates, which are opposite corners) and get a shorter list of co-ordinates of 3D quadrilaterals.

# Merging by creating a list with the first cube and another with the rest. # If the cube in the first list can be merged with a cube in the second list, # the cube in the second list is removed and the cube in the first list is # replaced with the merged shape. # If there is no suitable merge to be done, the lowest positioned cube in # the second list is moved to the first list and then we check if # anything in the second list can be merged with it and so on.  # loops until qbs has been emptied into css # the condition for merging is matching faces def xmerge(qbs, css):     tot = len(qbs)     j = 0     while len(qbs) > 0:         i = 0         k = 0         printProgressBar(tot - len(qbs)+1, tot, prefix = ' Merging along x:',         length = 50)         while i < len(qbs):             # first check if faces are touching             if (abs(css[j][0] - css[j][3]) == abs(css[j][0] - qbs[i][0])             and css[j][1] == qbs[i][1]             and css[j][2] == qbs[i][2]             # if true up to here then corners are touching             # below we check if the faces match (same size)             and abs(css[j][1] - css[j][4]) == abs(qbs[i][1] - qbs[i][4])             and abs(css[j][2] - css[j][5]) == abs(qbs[i][2] - qbs[i][5])):                 css[j] = [css[j][0],css[j][1],css[j][2],                 qbs[i][3],qbs[i][4],qbs[i][5]]                 qbs = np.delete(qbs, i, axis=0)                 k = 1             i += 1          if k == 0:             css = np.vstack([css, qbs[np.argmin(qbs[:,0])]])             qbs = np.delete(qbs, np.argmin(qbs[:,0]), axis=0)             j += 1      print("")     return css