Created
April 14, 2017 06:29
-
-
Save spin-glass/99482d628625f3109629862fb0aa0b83 to your computer and use it in GitHub Desktop.
リスト内の連続で値を持つような場合、その期間と期間内の平均のリストが欲しい
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lists = [0, 1, 2, 0, 1, 4, 0, 2, 3, 3] | |
# periods = [2, 2, 3] | |
# average = [1.5, 2.5, 2.6] | |
# が欲しい | |
periods = [] | |
average = [] | |
amount = 0 | |
k = 0 | |
period = 0 | |
for i, list in enumerate(lists): | |
if i >= k + period: | |
if list > 0: | |
period = 1 | |
amount = list | |
k = i | |
while len(lists) > k+1 and lists[k+1] > 0: | |
period += 1 | |
amount += lists[k+1] | |
k += 1 | |
print(period, amount/period) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment