Python 二维阵列团队 Table

Python 2D Arrays Team Table

我正在尝试弄清楚二维数组是如何工作的,如果有人可以向我解释你如何使用二维数组编写 table 代码,这将会有所帮助,其中一列中有团队 1 和 2,并且每个玩家在第二列中都有一个点值。完成后,我需要能够将第 1 队的得分和第 2 队的得分相加。总共有 20 名球员。

谢谢!

查看以下示例:

# Two 1D arrays
team1_scores = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
team2_scores = [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]

# This is your 2D array
scores = [ team1_scores, team2_scores ]

# You can sum an array using pythons built-in sum method
for idx, score in enumerate(scores):
    print 'Team {0} score: {1}'.format(idx+1, sum(score))

# Add a blank line
print ''

# Or you can manually sum each array
# Iterate through first dimension of array (each team)
for idx, score in enumerate(scores):
    team_score = 0
    print 'Summing Team {0} scores: {1}'.format(idx+1, score)
    # Iterate through 2nd dimension of array (each team member)
    for individual_score in score:
        team_score = team_score + individual_score
    print 'Team {0} score: {1}'.format(idx+1, team_score)

Returns:

Team 1 score: 55
Team 2 score: 65

Team 1 score: 55
Team 2 score: 65

Here 是关于 python 列表的更多信息。