sleeps=[{"summaryId ": "x209bf59-59b0c5a8-585c ",
"validation ": "AUTO_TENTATIVE ",
"durationInSeconds ": 22620,
"startTimeInSeconds ": 1504757160,
"awakeDurationInSeconds ": 900,
"startTimeOffsetInSeconds ": -14400,
"deepSleepDurationInSeconds ": 8160,
"lightSleepDurationInSeconds ": 13560},
{"summaryId ": "x209bf59-59b0c5a8-23a0 ",
"validation ": "AUTO_TENTATIVE ",
"durationInSeconds ": 9120,
"startTimeInSeconds ": 1504757160,
"awakeDurationInSeconds ": 300,
"startTimeOffsetInSeconds ": -14400,
"deepSleepDurationInSeconds ": 1680,
"lightSleepDurationInSeconds ": 7140}
]
res = sum([x["durationInSeconds"] for x in sleeps])
print(res)
これはKeyerror
を投げています。変更したいdictの特定の要素を追加する方法