Добавление целых чисел в список muti-line - PullRequest
0 голосов
/ 13 марта 2020
locations = ("Bowling Den", "Krazy Bowl", "City Bowl", "Top Bowling", "PinBowl")
games = ("10-Pin", "5-Pin", "Candlepin")
gamesPlayed = [[100, 250, 200],
               [500, 600, 700],
               [200, 225, 230],
               [120, 520, 500],
               [405, 60, 255]]

Я пытаюсь сослаться на колонки 0, 1 и 2 игр, сыгранных для:

print ("10-Pin", *total amount in column*)
print ("5-Pin", *total amount in column*)
print ("CandlePin", *total amount in column*)

1 Ответ

1 голос
/ 13 марта 2020

Используйте sum () для понимания списка:

print ("10-Pin",    sum(row[0] for row in gamesPlayed)) 
print ("5-Pin",     sum(row[1] for row in gamesPlayed))
print ("CandlePin", sum(row[2] for row in gamesPlayed))

вывод:

10-Pin 1325
5-Pin 1655
CandlePin 1885
...