teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コードの追加

2020/06/15 11:14

投稿

ha_horse
ha_horse

スコア20

title CHANGED
File without changes
body CHANGED
@@ -42,4 +42,23 @@
42
42
 
43
43
 
44
44
  どなたかこの計算プログラムをご教授いただけないでしょうか。
45
- やること自体は単純なのですが、forループでのdataのindex取得が上手くできません。
45
+ やること自体は単純なのですが、forループでのdataのindex取得が上手くできません。
46
+
47
+ ---
48
+ ご指摘をいただいたので、途中までのコードを載せます。
49
+
50
+ ```Python
51
+ w_matrix = []
52
+ for i in range(len(data)):
53
+ cnt = 0
54
+ for j in range(len(data[i])):
55
+ temp_list = []
56
+ if data[i][j] == data[i+j][j]:
57
+ cnt += 1
58
+ temp_list.append(cnt)
59
+
60
+ w_matrix.append(temp_list)
61
+ ```
62
+ 特に if data[i][j] == data[i+j][j]:
63
+ のインデックス参照部分がわかっておりません。
64
+ temp_list.append(cnt)の位置もおかしいです。