これはあなたのグラフの質問に答えていないが、あなたは確かに少なくとも2つの方法でリストのリストに頼ることなく、Pythonで2Dのリストを実装することができます
あなたは単に辞書を使用することができます。
import collections
t = collections.defaultdict(int)
t[0, 5] = 9
print t[0, 5]
これはまた、それが疎であるという利点を有する。
より多くの作業が必要な場合は、1dリストを使用して、テーブルの高さと幅とともに2次元座標を使用してインデックスを計算することができます。
class Table(object):
def __init__(self, width, height):
self._table = [None,] * (width * height)
self._width = width
def __getitem__(self, coordinate):
if coordinate[0] >= width or coordinate[1] >= height:
raise IndexError('Index exceeded table dimensions')
if coordinate[0] < 0 or coordinate[1] < 0:
raise IndexError('Index must be non-negative')
return self._table[coordinate[1] * width + coordinate[0]]
def __setitem__(self, coordinate, value):
if coordinate[0] >= width or coordinate[1] >= height:
raise IndexError('Index exceeded table dimensions')
if coordinate[0] < 0 or coordinate[1] < 0:
raise IndexError('Index must be non-negative')
self._table[coordinate[1] * width + coordinate[0]] = value
t = Table(10,10)
t[0, 5] = 9
print t[0, 5]
なぜリストはPythonicではないのですか? 2DリストはPythonでよく使われています。うまく開発された[numpy.ndarray](http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html)を使用することもできます。これは、n次元配列を実装し、行単位またはカラム。 –