How To: "Chunk" a List (convert a single list to a list of sublists of equal length)

Herewith a quick guide on making sublists out of a single list.

Blocks approach:

  1. Choose your divisor (how long will each sublist be)
  2. Get your "flat" list to be chunked
  3. The main procedure will then:
  • normalise the original list, that is to add empty list items, as required, so that the list is divisible by the divisor
  • break out the original list into chunks, and return a new chunked list of lists

Blocks (draggable):

Screen:

AIA:

ChunkAList.aia (3.5 KB)

The demo aia is setup to show the original list being chunked from 1 to 12. In practice you will only need the divisor of your choice.

I used this approach to organise a flat list of images into rows with 3 columns in order to display them "gallery style" using dynamic components.

If you really do not need the empty list items, you can remove them using list blocks, but it makes more sense to keep the list of lists normalised in most instances.

1 Like

Thank you Master Tim, for you great contributions.