回答編集履歴
1
obj -> dic
test
CHANGED
@@ -14,15 +14,15 @@
|
|
14
14
|
]
|
15
15
|
|
16
16
|
### 1科目、指定して取り出したい
|
17
|
-
subject_maths = [
|
17
|
+
subject_maths = [dic for dic in list1 if dic['科目'] == '算数']
|
18
18
|
print(subject_maths)
|
19
19
|
|
20
20
|
### 全科目、それぞれ取り出したい
|
21
|
-
subjects = list(set([
|
21
|
+
subjects = list(set([dic['科目'] for dic in list1])) # ['理科', '国語', '社会', '算数']
|
22
22
|
subject_all = []
|
23
23
|
|
24
24
|
for s in subjects:
|
25
|
-
subject_all.append([
|
25
|
+
subject_all.append([dic for dic in list1 if dic['科目'] == s])
|
26
26
|
|
27
27
|
print(subject_all) # 2次元リスト
|
28
28
|
print(subject_all[0]) # 1科目だけ抜き出し
|