So I have this code:
Team1 = ["Red", 10]
Team2 = ["Green", 5]
Team3 = ["Blue", 6]
Team4 = ["Yellow", 8]
Team5 = ["Purple", 9]
Team6 = ["Brown", 4]
TeamList = [Team1, Team2, Team3, Team4, Team5, Team6]
I want to make a two-dimensional list of difference in scores between each pair of teams.
The output can be like this:

What is the easiest way to do this? Thanks :)
You could try:
[[x[1]-y[1] for y in TeamList] for x in TeamList]
That will generate a nested list representing the proposed output (without the column and row headings, of course).
Just using tabs rather than any fancy formatting to build the chart:
Team1 = ["Red", 10]
Team2 = ["Green", 5]
Team3 = ["Blue", 6]
Team4 = ["Yellow", 8]
Team5 = ["Purple", 9]
Team6 = ["Brown", 4]
TeamList = [Team1, Team2, Team3, Team4, Team5, Team6]
# print the top row of team names, tab separated, starting two tabs over:
print '\t\t', '\t'.join(team[0] for team in TeamList)
# for each row in the chart
for team in TeamList:
# put two tabs between each score difference column
scoreline = '\t\t'.join(str(team[1] - other[1]) for other in TeamList)
# and print the team name, a tab, then the score columns
print team[0], '\t', scoreline
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With