Python Balanced sports schedule generation
<p>I have the following code sample</p>

<pre><code>import itertools
import random
set_size = 2
schedule = set()
teams = range(10)
for comb in itertools.product(teams, repeat=set_size):
    comb = sorted(list(comb))
    if len(set(comb)) == set_size:
        schedule.add(tuple(comb))

schedule = list(schedule)
random.shuffle(schedule)

home = {}
for game in schedule:
    if home.has_key(game[0]):
        home[game[0]] += 1
    else:
        home[game[0]] = 1


print home
</code></pre>

<p>It generates a valid schedule but the issue is some of the teams are very lopsided for home games. </p>

<p>For example a print out of home is</p>

<pre><code>{0: 5, 1: 3, 2: 5, 3: 5, 4: 5, 5: 5, 6: 5, 7: 5, 8: 4, 9: 3}
</code></pre>

<p>The key is the team and the value is the number of home games. If I have 10 teams in a league I expect some teams to get 5 home and others to get only 4 but some get 5 while others are getting only 3</p>
