$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #40

What is the correct fix?

def chunk(lst, n):
    result = []
    for i in range(0, len(lst)):
        result.append(lst[i:i + n])
    return result
  1. Change lst[i:i + n] to lst[i:n] in body
  2. Change append to extend in the loop
  3. Start the range at 1 instead of 0 index
  4. Change range(0, len(lst)) to range(0, len(lst), n)
The step must be n so chunks do not overlap.
Play Problem Solving ▸