E
E
Eli_sh2017-02-12 19:28:22
Python
Eli_sh, 2017-02-12 19:28:22

Python. What does this line do?

Tell me, please, what does line three (Buf = [0]*K) mean in this program.

N = int(input())
K = 7
Buf = [0]*K
for i in range(N):
  elem = int(input())
  next = Buf[i % K] 
  Buf[i % K] = elem
  if i == K:
    maxPrev = next
    maxSum = next + elem
  if i > K:
    maxPrev = max(maxPrev, next)
    maxSum = max(maxSum, maxPrev+elem)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zergon321, 2017-02-12
​​@Eli_sh

Buf = [0]*K
is equivalent to the following construction:
I.e. Buf is a list, each element of which is 0.

I
igor travov, 2017-02-12
@estj

list multiplication. Sit in a shell and practice....
>>> dd = [0] * 7
>>> dd
[0, 0, 0, 0, 0, 0, 0]
>>>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question