[初学者提醒] 我正在编写代码并记录它们的变化。我想将这个 for 循环的变体组合在一个文件中,但只执行第一个。为什么以及我必须做什么才能实现这一目标?
teams = ['Dragons', 'Wolves', 'Pandas', 'Unicorns']
n = 1
for home_team in teams:
for away_team in teams[n:]: # This block causes the execution to increase n by one
if home_team != away_team: # for every away_team in one home_team
print(home_team, away_team) # then proceeds to the next home_team
n += 1
for home_team in teams:
for away_team in teams[n:]: # This block causes the execution to increase n by one
if home_team != away_team: # for every home_team
print(home_team, away_team)
n += 1