Editor settings

General settings

Save settings

Learn to program with Python

Chunking a list #

Write a function that takes a list and a specific chunk length as input and returns a new list with sublists, where each sublist has the specified chunk length.


Tests #

  • chunk_it_up([1, 2, 3, 4, 5, 6, 7, 8], 2) should return [[1, 2], [3, 4], [5, 6], [7, 8]].
  • chunk_it_up(['apple', 'banana', 'orange', 'grape', 'kiwi', 'mango'], 4) should return [['apple', 'banana', 'orange', 'grape'], ['kiwi', 'mango']].
  • chunk_it_up([True, False, True, True], 1) should return [[True], [False], [True], [True]].
  • chunk_it_up([10, 20, 30, 40, 50], 6) should return [[10, 20, 30, 40, 50]].
  • chunk_it_up([], 3) should return [].
Output will be displayed here