0

Suppose I have an array/list like this:

 a =[5,8,9,6,5,4,5,6,1]

Then the Output should be:

 a =[[5,8],[9,6],[5,4],[5,6],[1]]

It's not necessary that I have to combine every two elements. It can be 2 or 3 or 4 but that's something I should be able to decide. I tried it multiple ways but was unable to achieve the result

Any help is appreciated.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Shadow Fiend
  • 45
  • 1
  • 2
  • 9
  • 6
    Possible duplicate of [How do you split a list into evenly sized chunks?](https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks) – Mr. T Dec 16 '17 at 01:35

1 Answers1

0

It might be helpful:

You could be able to turn this into a function without problem

enter image description here

Moreno
  • 608
  • 1
  • 9
  • 24