回答編集履歴

3

f

2020/10/20 10:09

投稿

sfdust
sfdust

スコア1137

test CHANGED
@@ -6,11 +6,11 @@
6
6
 
7
7
  result = [
8
8
 
9
- {'name': 'yamada', 'weight': '72', 'height':180},
9
+ {'name': 'yamada', 'weight': '72', 'height':'180'},
10
10
 
11
- {'name': 'yamada', 'weight': '73', 'height':180},
11
+ {'name': 'yamada', 'weight': '73', 'height':'180'},
12
12
 
13
- {'name': 'yamada', 'weight': '75', 'height':180},
13
+ {'name': 'yamada', 'weight': '75', 'height':'180'},
14
14
 
15
15
  ]
16
16
 
@@ -110,23 +110,23 @@
110
110
 
111
111
  "weight": "72",
112
112
 
113
- "height": 180
113
+ "height": "180"
114
114
 
115
115
  },
116
116
 
117
117
  {
118
118
 
119
- "weight": "74",
119
+ "weight": "73",
120
120
 
121
- "height": 182
121
+ "height": "180"
122
122
 
123
123
  },
124
124
 
125
125
  {
126
126
 
127
- "weight": "54",
127
+ "weight": "75",
128
128
 
129
- "height": 170
129
+ "height": "180"
130
130
 
131
131
  }
132
132
 

2

2020/10/20 10:09

投稿

sfdust
sfdust

スコア1137

test CHANGED
@@ -8,9 +8,9 @@
8
8
 
9
9
  {'name': 'yamada', 'weight': '72', 'height':180},
10
10
 
11
- {'name': 'yamada', 'weight': '74', 'height':182},
11
+ {'name': 'yamada', 'weight': '73', 'height':180},
12
12
 
13
- {'name': 'yamada', 'weight': '54', 'height':170},
13
+ {'name': 'yamada', 'weight': '75', 'height':180},
14
14
 
15
15
  ]
16
16
 

1

修正

2020/10/20 10:08

投稿

sfdust
sfdust

スコア1137

test CHANGED
@@ -6,17 +6,15 @@
6
6
 
7
7
  result = [
8
8
 
9
- {'name': 'yamada', 'weight': '72', 'height':180},
9
+ {'name': 'yamada', 'weight': '72', 'height':180},
10
10
 
11
- {'name': 'yamada', 'weight': '74', 'height':182},
11
+ {'name': 'yamada', 'weight': '74', 'height':182},
12
12
 
13
- {'name': 'satou', 'weight': '54', 'height':170},
13
+ {'name': 'yamada', 'weight': '54', 'height':170},
14
-
15
- {'name': 'satou', 'weight': '58', 'height':172},
16
-
17
- {'name': 'tanaka', 'weight': '42', 'height':149}
18
14
 
19
15
  ]
16
+
17
+
20
18
 
21
19
  ```
22
20
 
@@ -28,15 +26,13 @@
28
26
 
29
27
  ```
30
28
 
29
+
30
+
31
31
  def convert(src, keywords):
32
32
 
33
- # src :変換元データ
33
+ # 結果格納用辞書
34
34
 
35
- # keywords : 抽出するカラムを指定したリスト
36
-
37
-
38
-
39
- dest = dict() # 結果格納用の辞書
35
+ dest = dict()
40
36
 
41
37
  for src_item in src:
42
38
 
@@ -44,7 +40,9 @@
44
40
 
45
41
  name = src_item.get('name')
46
42
 
43
+ dest.setdefault("name", name)
44
+
47
- dest.setdefault(name, {"DataList":[]})
45
+ dest.setdefault("DataList", [])
48
46
 
49
47
  # DataListに格納する個別データ
50
48
 
@@ -58,9 +56,11 @@
58
56
 
59
57
  if datalist_item:
60
58
 
61
- dest[name]["DataList"].append(datalist_item)
59
+ dest["DataList"].append(datalist_item)
62
60
 
63
61
  return dest
62
+
63
+
64
64
 
65
65
  ```
66
66
 
@@ -102,69 +102,35 @@
102
102
 
103
103
  {
104
104
 
105
- "yamada": {
105
+ "name": "yamada",
106
106
 
107
- "DataList": [
107
+ "DataList": [
108
108
 
109
- {
109
+ {
110
110
 
111
- "weight": "72",
111
+ "weight": "72",
112
112
 
113
- "height": 180
113
+ "height": 180
114
114
 
115
- },
115
+ },
116
116
 
117
- {
117
+ {
118
118
 
119
- "weight": "74",
119
+ "weight": "74",
120
120
 
121
- "height": 182
121
+ "height": 182
122
122
 
123
- }
123
+ },
124
124
 
125
- ]
125
+ {
126
126
 
127
- },
127
+ "weight": "54",
128
128
 
129
- "satou": {
129
+ "height": 170
130
130
 
131
- "DataList": [
131
+ }
132
132
 
133
- {
134
-
135
- "weight": "54",
136
-
137
- "height": 170
138
-
139
- },
140
-
141
- {
142
-
143
- "weight": "58",
144
-
145
- "height": 172
146
-
147
- }
148
-
149
- ]
133
+ ]
150
-
151
- },
152
-
153
- "tanaka": {
154
-
155
- "DataList": [
156
-
157
- {
158
-
159
- "weight": "42",
160
-
161
- "height": 149
162
-
163
- }
164
-
165
- ]
166
-
167
- }
168
134
 
169
135
  }
170
136