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]]
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]]
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]])
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]])
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]]