Code:
import random
group = [[]*10 for i in range(0,8)]
#-----------------------------------------
group[0] = [1,5,9,13,17,21,25,29,33,37]
group[1] = [41,45,49,53,57,61,65,69,73,77]
#-----------------------------------------
group[2] = [2,6,10,14,18,22,26,30,34,38]
group[3] = [42,46,50,54,58,62,66,70,74,78]
group[4] = [3,7,11,15,19,23,27,31,35,39]
group[5] = [43,47,51,55,59,63,67,71,75,79]
group[6] = [4,8,12,16,20,24,28,32,36,40]
group[7] = [44,48,52,56,60,64,68,72,76,80]
#-----------------------------------------
row = [0]*10
temp =[0]*10
for i in range(0,10):
row[i] = []
temp[i] = []
for i in range(0,8):
place = 0
for j in range(0,10):
place = random.randint(place,j)
temp[place] = temp[place][:]+[group[i][j]]
white = 0
place = 9
print temp
for j in range(0,10):
if len(temp[place]) == 0:
white = white +1
else:
newrow =random.randint(place,place+white)
temp[newrow] = temp[place]
if newrow != place:
temp[place] = []
white = newrow -place
place = place -1
print temp
for j in range(0,10):
if len(temp[j]) != 0:
row[j] = row[j][:] +temp[j][:]
temp[j] = []
for i in range(0,10):
print row[i]