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
- Change
lst[i:i + n]tolst[i:n]in body - Change
appendtoextendin the loop - Start the range at 1 instead of 0 index
- Change
range(0, len(lst))torange(0, len(lst), n)
The step must be
Play Problem Solving ▸
n so chunks do not overlap.