1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| import random
def interview(GroupList): result = [[]] bit_index = 0 grouplist_y = len(GroupList) grouplist_x = len(GroupList[0]) last_index = -1
while bit_index < grouplist_y: rand_y = random.randint(0, grouplist_y-1) if last_index == rand_y: continue
rand_x = random.randint(0, grouplist_x-1) if len(GroupList[rand_y]) == 0 or len(GroupList[rand_y]) <= rand_x: continue val = GroupList[rand_y][rand_x] GroupList[rand_y] = GroupList[rand_y][:rand_x] + GroupList[rand_y][rand_x + 1:] result[len(result) - 1].append(val) last_index = rand_y if len(result[len(result) - 1]) >= 2: last_index = -1 result.append([])
if len(GroupList[rand_y]) == 0: bit_index += 1 if len(result[len(result) - 1]) == 1: temp = result[len(result)-1] result = result[:len(result) - 1] result[len(result) - 1].extend(temp)
if len(result[len(result) - 1]) == 0: return result[:len(result) - 1]
return result
if __name__ == '__main__': GroupList = [ ['小名', '小红', '小马', '小丽', '小强'], ['大壮', '大力', '大1', '大2', '大3'], ['阿花', '阿朵', '阿蓝', '阿紫', '阿红'], ['A', 'B', 'C', 'D', 'E'], ['一', '二', '三', '四', '五'], ['建国', '建军', '建民', '建超', '建跃'], ['爱民', '爱军', '爱国', '爱辉', '爱月'] ]
result = interview(GroupList) print(result)
|