次のコードを考慮してください。二乗リスト作成時のIndexError
start_list = [5, 3, 1, 2, 4]
square_list = []
for i in start_list:
square_list.append(start_list[i]**2)
print square_list
このコードは、start_listを反復処理し、各二乗を四角形リストに追加するためのものです。だから、出力があることを意味する:
[25, 9, 1, 4, 16]
その代わり、私が取得:
Traceback (most recent call last):
File "python", line 4, in <module>
IndexError: list index out of range
どうもありがとうございました。 ;) –
あなたの大歓迎 –