所以我有这个密码:

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]

我想做一个两个队得分差异的二维列表。
输出可以如下:
最简单的方法是什么?谢谢:)

最佳答案

只是使用制表符而不是任何花哨的格式来构建图表:

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

08-16 16:15