私はリスト(g.ordered)を持っており、そのリストに正しい順序で要素を追加したいと思います。 g.orderedが構成されていますTypeerror添え字なし
# all values are floats
g.ordered = [
[[a, b, c, d...], [A]],
[[e, f, g, h...], [B]]...
]
# Where A is < B is < ...
私は動作するはずの機能を書かれている
x = [[q, w, e, r...], [C]]
# Where C can be any float
を追加したい:
def insert(x):
for i in range(len(g.ordered)):
print(g.ordered[i][1])
print(x[1])
if(g.ordered[i][1] > x[1]):
break
g.ordered = g.ordered[:i] + x + g.ordered[i:]
今、私はいけない部分を理解: ときIそれを印刷するプリントステートメントを含めます:
>>> g.ordered[0][1]
A
>>> X[1]
C
しかし、それが印刷されると、エラーが表示されます。
print(g.ordered[i][1])
TypeError: 'float' object is not subscriptable
これは、次の行がすでに完了した後です。
プリントと完全なエラー:
-4.882695743122578 # this is the A value
0.01 # this is the C value
# those where the expected prints which are in line 50 and 51 respecively
Traceback (most recent call last):
File "/home/jjrreett/Genetic.py", line 57, in <module>
insert([[1,2,3,4,5], 0.01])
File "/home/jjrreett/Genetic.py", line 50, in insert
print(g.ordered[i][1])
はTypeError: 'フロート' オブジェクトは、添字化
at line 49 print g.ordered [i]浮動小数点の場合は答えが間違っています – awiebe