Skip to content

Instantly share code, notes, and snippets.

@ZSendokame
Last active November 18, 2023 16:50
Show Gist options
  • Save ZSendokame/66aabedcfd2166fd184ca828390764d5 to your computer and use it in GitHub Desktop.
Save ZSendokame/66aabedcfd2166fd184ca828390764d5 to your computer and use it in GitHub Desktop.
Wrap an array in n-Sized groups, wrap([1, 2, 3, 4, 1, 2, 3, 4], 4) -> [[1, 2, 3, 4], [1, 2, 3, 4]]
def wrap(array, size) -> list:
result = []
aux_array = []
for i in array:
aux_array.append(i)
if len(aux_array) == size:
result.append(aux_array)
aux_array = []
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment