how to vonvert 1 d list to 2d list in pytohn

Solutions on MaxInterview for how to vonvert 1 d list to 2d list in pytohn by the best coders in the world

showing results for - "how to vonvert 1 d list to 2d list in pytohn"
Ana
07 Aug 2019
1In [53]: l = [0,1,2,3]
2
3In [54]: def to_matrix(l, n):
4    ...:     return [l[i:i+n] for i in xrange(0, len(l), n)]
5
6In [55]: to_matrix(l,2)
7Out[55]: [[0, 1], [2, 3]]