0

I have the list:

[0, 15, 19, 26, 34, 62]

How would I go about converting it into the following?

[[0, 15], [19, 26], [34, 62]]
accdias
  • 5,160
  • 3
  • 19
  • 31

3 Answers3

2

You can use numpy:

import numpy as np

arr = [0, 15, 19, 26, 34, 62]
np.reshape(arr, (-1, 2))

output:

array([[ 0, 15],
       [19, 26],
       [34, 62]])
Shahab Rahnama
  • 982
  • 1
  • 7
  • 14
0
list = [0, 15, 19, 26, 34, 62]

new_list = []
for i in range(0, len(list), 2):
    new_list.append([list[i], list[i+1]])
KillerRebooted
  • 470
  • 1
  • 12
0

A simple solution, list members must be even.

>>> a = [0, 15, 19, 26, 34, 62]
>>> [[a[l*2], a[l*2 + 1]] for l in range(int(len(a)/2))]
[[0, 15], [19, 26], [34, 62]]
Yuri
  • 511
  • 3
  • 6