H=[]
x=0
while x<10:
H[0][x]=1
x+=1
print H
Traceback (most recent call last):
File "D:\mydoc\NetBeansProjects\test\massiv2d.py", line 14, in <module>
H[0][x]=1
IndexError: list index out of range
[[0 for col in range(10)] for row in range(10)]
H=[]
x=0
while x<10:
H[0][x]=1
x+=1
print H
Traceback (most recent call last):
File "D:\mydoc\NetBeansProjects\test\massiv2d.py", line 14, in <module>
H[0][x]=1
IndexError: list index out of range
[[0 for col in range(10)] for row in range(10)]
hellsladeok, спасибо
Просто объявить не получится. Или заполняйте чем-то или попробуйте import array
>>> h = [[]]
>>> for i in xrange(10):
h[0].append(1)
>>> h
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
>>>