2019-01-06

import pprint


class Value:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    
    def __repr__(self):
        return f'{type(self).__name__}({self.x}, {self.y})'


def create_2D_list(a, b):
    _2D_list = []
    for i in range(a):
        _1D_list = []
        _2D_list.append(_1D_list)
        for j in range(b):
            _1D_list.append(Value(i, j))
    return _2D_list


pprint.pprint(create_2D_list(2, 3))
# [[Value(0, 0), Value(0, 1), Value(0, 2)],
#  [Value(1, 0), Value(1, 1), Value(1, 2)]]

記事への反応(ブックマークコメント)

ログイン ユーザー登録
ようこそ ゲスト さん