需求描述:8个字母随机分成三组
import random #构造存储的数据结构 offices = [[],[],[]] names = ['A','B','C','D','E','F','G','H'] #循环遍历随机分配到三个列表 for name in names: index = random.randint(0,2) offices[index].append(name) #输出随机分配结果 for row in offices: for i in row: print(i,end="") print("\n",end="") print("---"*10)