Python2D数组团队表

Python2D数组团队表,python,arrays,2d,Python,Arrays,2d,我正在试图弄清楚2D数组是如何工作的,如果有人能向我解释一下如何使用2D数组编码一个表,其中一列中有第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

我正在试图弄清楚2D数组是如何工作的,如果有人能向我解释一下如何使用2D数组编码一个表,其中一列中有第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)
返回:

Team 1 score: 55
Team 2 score: 65

Team 1 score: 55
Team 2 score: 65

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

阅读列表。2D数组通常使用列表列表在Python中实现。