I use Python 2.6.
My code can be edited and run here: http://www.codeskulptor.org/#user12_OQL53Z5Es8yDHRB.py
# set the arguments
teams = 4
rounds = 2 * (teams - 1)
# show the arguments
print teams, "teams"
print rounds, "rounds"
# season is a list of lists
# each sub list is a round
season = rounds*["round"]
# store the first round in season[0]
round = range(1, teams + 1)
season[0] = round[:]
# store the other rounds in season
for j in range(1, rounds):
round2 = round[:]
round2[1] = round[teams - 1]
for i in range(2, teams):
round2[i] = round[i - 1]
season[j] = round2[:]
round = round2
# print the season
print season
If there are 4 teams and everyone plays every team twice I want this end result: [1, 2, 3, 4], [1, 4, 2, 3], [1, 3, 4, 2], [1, 2, 3, 4], [1, 4, 2, 3], [1, 3, 4, 2]]. Team 1 stays put and the other teams rotate. Every team moves one position to the right, except team 1 and the last team in the list which moves to the position next to team 1.
I believe the above code works. I am a newbie in Python, so I am looking for better or more elegant code.
Thank you!