Заканчивать следующий пример:
# 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
Here является больше информации о списках питона.
Читайте в списках. 2D-массивы обычно реализуются в Python, используя списки списков. –