如何建立随机的团队生成器?

时间:2019-10-30 06:45:23

标签: python

如何使用python构建随机团队生成器?我有一个60人的团队,希望将他们分为10组。

1 个答案:

答案 0 :(得分:1)

最简单的方法可能是将原始池洗牌并切片:

import random

pool = list(range(60))  # or some other list of length 60
random.shuffle(pool)

teams = [pool[i:i+6] for i in range(0, 60, 6)]
teams
[[28, 7, 59, 43, 2, 39],
 [26, 53, 33, 3, 17, 34],
 [9, 21, 58, 36, 37, 4],
 [57, 38, 56, 15, 23, 1],
 [10, 49, 52, 0, 40, 13],
 [27, 14, 35, 47, 45, 18],
 [12, 46, 6, 55, 11, 30],
 [19, 22, 54, 41, 16, 20],
 [50, 44, 29, 48, 8, 42],
 [5, 51, 25, 31, 32, 24]]