Thanks for the comments all- I managed to get it working by adding 'return' to the one_counter() function. One follow on question if I may- do we always need to 'return' something for every function? Because I came across some other code that doesn't do this, here it is:
def maxSlidingWindow(nums: List[int], k: int) -> List[int]:
d = deque() # keep this monotonic
def eat(i):
# kick from the back all indeces of smaller numbers that came before
while d and nums[d[-1]] <= nums[i]:
d.pop()
d.append(i)
def spit(i):
# kick index out the front if still present
if i == d[0]:
d.popleft()
for i in range(k-1):
# first, fill sliding window except one
eat(i)
def slide():
# then: consume next slot -> yield max -> eject last
for i in range(k-1, len(nums)):
eat(i)
yield nums[d[0]]
spit(i-k+1)
return list(slide())
Can someone please briefly explain when we use return and when we don't need it like in the above? Thanks!
Specifically when calling another function from within the same class- when do we need to have 'return'
and when do we not?