Created
January 17, 2017 05:26
-
-
Save KentaYamada/238875717108dbc7a3e5bc51afc239a4 to your computer and use it in GitHub Desktop.
1次元配列から2次元配列へ変換する関数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_2dimentional_list(arr, row_no, col_no): | |
res = [] | |
offset = 0 | |
for row in range(0, row_no): | |
res.append(arr[offset:col_no+offset]) | |
offset = offset + col_no | |
return res | |
a = [1,2,3,4,5,6] | |
b = to_2dimentional_list(a, 2, 3) | |
print(b) # [[1, 2, 3], [4, 5, 6]] | |
c = to_2dimentional_list(a, 3, 2) | |
print(c) # [[1, 2], [3, 4], [5, 6]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment