Here's part of my Python code, I'm trying to find the 4 consecutive values in spec
which yields the maximum sum, and then find the weighted average value of the corresponding 4 keys:
spec = {1.5:8, 1.3:9, 4.3:7, 3.2:3, 5.3:5, 4:1, 5.2:6, 4.2:4, 2.5:9}
k = 4
consecutive_elements = zip(*(islice(spec.values(), x, None) for x in range(k)))
max(map(sum, consecutive_elements)) # The maximum sum.
Wavg = np.average(list(???.keys()), weights=list(???.values())) # The weighted average
I'm not sure how I can access the 4 keys. In this case, they should be 1.5, 1.3, 4.3, 3.2
since the sum of their values is 27 (the maximum). Which tools should I use?