从python中的列表中选择数字

cha*_*ear 3 python random list

我正在制作一个能够产生单一淘汰赛的计划.到目前为止,我的代码看起来像这样(我刚刚开始)

amount = int(raw_input("How many teams are playing in this tournament?  "))
teams = []
i = 0
while i<amount:
    teams.append(raw_input("please enter team name:  "))
    i= i+1
Run Code Online (Sandbox Code Playgroud)

现在我被卡住了.我想随机选择2个数字,这些数字将选择面向对方的球队.数字根本不能重复,并且必须从1到"数量".最有效的方法是什么?

Ter*_*ryA 11

看看random模块.

>>> import random
>>> teams = ['One team', 'Another team', 'A third team']
>>> team1, team2 = random.sample(teams, 2)
>>> print team1
'Another team'
>>> print team2
'One team'
Run Code Online (Sandbox Code Playgroud)